Reputation: 4023
Given the following pseudo code, how could i call this function with .Include
and pass it on to ctx.Table
public class Complicated
{
// fields here
}
public IEnumerable<Complicated> GetComplicatedData<T>()
{
using(MyDbCtx ctx = new MyDbCtx())
{
return ctx.Set<T>().Select(p=> new Complicated { /* fill */ }).ToList();
}
}
Upvotes: 0
Views: 473
Reputation: 364279
You can't. Your method is doing projection so even if you find the way your include will never be used. If you want to use Include you must use a method this way:
ctx.Table.Include(...).ToList().Select(p => new Complicated { ... });
This example doesn't make much sense because you know what data you need to fill your Complicated
item so you can either fill them directly by linq-to-entites without using Include
at all or you know upfront what includes will you need to fill your Complicated
entity by linq-to-objects.
There is no eager or lazy loading for custom projected classes.
Upvotes: 1