I have this simple code, using EF Core 2.
I perform 2 subqueries and the result is the Union of them. The problem is that the Include
method in after the Union
doesn't load the navigation properties (Role
is always null
).
public static void Main()
{
using (var context = new MyDbContext())
{
IQueryable<User> a = SomeQuery(context);
IQueryable<User> b = SomeOtherQuery(context);
var union = a.Union(b);
var resultingList = union.Include(x => x.Role); // Include doesn't work
}
}
What should I do to effectively load navigation properties after composing with the Union method?
NOTE: The problem also happens with the Concat
method.
ToList()
I tried here and it works.var resultingList = union.Include(x => x.Role).ToList();