我有这个查询
var test = context.Assignments
.Include(a => a.Customer)
.Include(a => a.Subscriptions)
.Select(a => new AssignmentWithSubscriptionCount { SubscriptionCount = a.Subscriptions.Count(), Assignment = a })
.ToList();
var name = test.First().Assignment.Customer.Name;
它无法急切地加载客户,我在 stackoverflow 上看到过类似的问题,而且看起来您不能将投影与包含一起使用。但是我还没有找到解决我的问题的方法..有人吗?
编辑:这是一个热切负载的投影,它比上面的例子更复杂,所以我一生都无法理解出了什么问题,谢谢。
var test = context.PublicationStateGroups
.Include(p => p.PublicationStates.Select(ps => ps.AllowedPublicationStateActions.Select(aps => aps.PublicationStateAction)))
.Select(psg => new StateAndGroupInfo
{
ShowReport = psg.PublicationStates.Any(p => p.PublicationStateReportTypeId.HasValue),
Actions = psg.PublicationStates.SelectMany(state => state.AllowedPublicationStateActions)
.Select(a => a.PublicationStateAction)
.Distinct()
}).ToList();
var eagerTest = test.First().Actions.First().Name;
最佳答案
这是by design . Include
不适用于具有投影或自定义连接的场景。
关于包含投影不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7917348/