c# - How should I be using repository? -


i'm trying implement repository, having trouble in application layer.

note:

  • transactionmodel nhibernate entity lazy loading
  • transaction application level object
  • mapper automapper, not relevant problem, no tag added this

i used have in application layer:

public transaction gettransaction(string itemname) {   using (var context = _sessionfactory.opensession())   {     var tran = context.get<transactionmodel>(itemname);     return mapper.map<transaction>(tran);   } } 

which worked, since introducing repo clean app layer, problems mapping caused lazy loading nhibernate.lazyinitializationexception.

public transaction gettransaction(string itemname) {     var tran = _transactionrepository.getitem(itemname);     return mapper.map<transaction>(tran); } 

clearly problem context has been closed time mapping. how should using repository in conjunction context? should make context in application layer , pass repo? this:

public transaction gettransaction(string itemname) {   using (var context = _sessionfactory.opensession())   {     var tran = _transactionrepository.getitem(context, itemname);     return mapper.map<transaction>(tran);   } } 

this not affects mapping issue, other cases want read, modify , put transactionmodels


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -