3
Vote

EF Core .ThenInclude() support

description

Thanks for making such a user-friendly and flexible solution to the Generic Repository pattern. It's really helped us organise our code to keep dependencies on EF separated from the business layer.

We're creating a new project using .Net Core, and running into a snag when attempting to Include from a Many to Many relationship. In EF6, this would be written as follows:
.Include(x => x.Orders.Select(y => y.OrderDetails))
In EF Core, this syntax no longer seems to work correctly throwing the following error:
InvalidCastException: Unable to cast object of type 'Remotion.Linq.Clauses.Expressions.SubQueryExpression' to type 'System.Linq.Expressions.MemberExpression'.
This is because the new way of writing this in EF Core is:
.Include(x => x.Orders)
.ThenInclude(y => y.OrderDetails)
From looking at the EF Core code, .ThenInclude() is an extension method on an EF type IIncludableQueryable, so I'm not sure how to expose this in our business layer through IQueryFluent without a dependency on Entity Framework leaking in.

Can anyone give me some pointers on the best way to achieve this, since it seems like a nice API to Include.

Best Regards,

Paul

comments

snekkke wrote Jun 27, 2016 at 5:59 AM

Hi, any help on this??

lucaslessa wrote May 17 at 1:54 PM

Hi, I need the same solution!
Any help on this??

educielo wrote May 19 at 2:26 PM

I have Migrated this code base to EF Core. But one thing i cant get is on Insert, _dbSet.Attach(TEntity);
is not working. But _dbSet.Add(TEntity); works, I cant Figure it Out