c# - NHibernate Repository -


does has proper , simplified write on nhibernate repository? i've used java, hibernate, lcds dataservice repositories flexbuilder (using rtmp channelling) , want implement exact fundamental c#.net.

i've gone through lots of online documentation nothing reflecting exact use flexbuilder.

if has small example application share. helpful.

regards nitin

see these:

first create interface irepository:

public interface irepository<t> {     int add(t entity);     void delete(t entity);     void update(t entity);     t getbyid(int id);     ienumerable<t> findall(detachedcriteria criteria);     ...     .     .     // } 

then implement interface following:

 public class repository<t> : irepository<t> {     readonly iactivesessionmanager _activesessionmanager;     protected isession session     {         { return _activesessionmanager.getactivesession(); }     }     public repository(iactivesessionmanager activesessionmanager)     {         _activesessionmanager = activesessionmanager;     }     public int add(t entity)     {         int newid = (int)session.save(entity);         session.flush();         return newid;     }     .     .     // add remaining implementations } 

the implementation of activesessionmanager , sessionprovider simple , can find in previous links.

you can expose methods following:

 public t findone(nhibernate.criterion.detachedcriteria criteria)  {      return criteria.getexecutablecriteria(session).uniqueresult<t>();  } 

then:

public class entityrepository : repository<entity> {     public entityrepository(iactivesessionmanager activesessionmanger)         : base(activesessionmanger)     {     }     public entity getbyname(string name)     {         var criteria = nhibernate.criterion.detachedcriteria.for<entity>()             .add(restrictions.eq("name", name));         return findone(criteria);     }     public ilist<entity> returnsomething()     {     }     .... } 

this basic implementation pattern, can decorate design drive you.

you can go further, recommend, after understanding these pattern , implement it, checking out nhibernate , unit of work pattern


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -