mercredi 22 avril 2015

Encapsulate context constructor on a query object

It is a good idea to create a class that holds both the query and the context constructors as Func of Context and Func of IQueryable of TEntity for solving the context lifetime problem?

Example: On your data layer, if you use one context per method using the "using" statement, you can't return IQueryables because this wouldn't be valid after the context has been released, this makes you use of:

  • One context per form (This would need injecting the form context onto your data layer)
  • Thread static context
  • Call ToList() before returning the query (Disable query composition)

Aucun commentaire:

Enregistrer un commentaire