结构是基本的。我有一个“App”父级,它有许多“PositionData”子级。我想在单个查询中检索“App”的一些基本数据以及该 App 的最后一个“PositionData”。
查询
var data = context.Apps.Where(a => a.Id == appId).
Select(c => new {
DeviceInfo=c.Device,
LastPosition=c.PositionData.OrderByDescending(p=>p.DateCreated).FirstOrDefault()
}).SingleOrDefault();
执行以下命令会引发“System.NotImplementedException”
为了确保仅在子查询的情况下引发异常,我将其分为 2 个查询,它工作得非常好。
var tempObj = context.Apps.Where(a => a.Id == appId).SingleOrDefault();
var data=new {
DeviceInfo=tempObj.Device,
LastPosition=tempObj.PositionData.OrderByDescending(p=>p.DateCreated)).FirstOrDefault()
};
我已经搜索了很多天,也访问了 pg Foundry 论坛,但还没有解决方案。