Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

Commented Unassigned: EF Core .ThenInclude() support [1263]

$
0
0
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: Hi, I need the same solution! Any help on this??

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>