Getting encapsulation strategies for Entity Framework 4.1 and NHibernate

I created a project to test NHibernate 3+ and Entity Framework 4.1, wrapping it in a repository, making it very susceptible to testing using interfaces, etc.

I do not want to expose ORM outside of repositories (I do not even open IQueryables). Everything should be processed in this layer, and until I tried to process it in an abstract way, everything was fine.

A Microsoft implementation with impatient downloads uses either magic strings (yuck) or Linq expressions (yay) in the Include function. Their syntax follows something like this:

IQueryableThing.Include(o => o.Person);
IQueryableThing.Include(o => o.Company.Contact);
IQueryableThing.Include(o => o.Orders.Select(p => p.LineItem.Cost);

The first will just load the associated user. (Parent) The second will load the related company and each contact company. (parent and grandfather). The third will load all related orders, line items and costs for each order.

This is a pretty realistic implementation.

NHibernate takes a slightly different approach. They still use Linq expressions, but they more actively use extension methods (a smooth approach).

IQueryableThing.Fetch(o => o.Person);
IQueryableThing.Fetch(o => o.Company).ThenFetch(o => o.Contact);
IQueryableThing.FetchMany(o => o.Orders).ThenFetch(p => p.LineItem).ThenFetch(q => q.Cost);

(I'm not sure if the third line is the correct syntax)

I can encapsulate the list of expressions in a separate class, and then apply them to the IQueryable in this class. Therefore, I will need to standardize the syntax of the Microsoft expression, and then translate it into NHibernate syntax by going through the expression tree and rebuilding each expression.

, . , IQueryable ( Fetch FetchMany, "ThenFetch" ​​ "ThenFetchMany" ), , ExpressionVisitor.

: , , , . , Fetch extensions LambdaExpression .

, , Fetch nHibernate. , , , Remotion , .

.

+3
1

NHiberanteUtil.Initialize()? , , , Include().

0

All Articles