Vin*_*ens 12 linq entity-framework
我遇到了GROUP BY和急切加载的问题.我试着解释一下我在做什么.我正在查询datacontext ctx以查找事件
事件类具有以下属性
string Description
DateTime Date
bool IsDeleted
Guid SubjectId
string Title
DateTime Created
Guid ForProjectId
Person TriggeredBy
List<Guid> Targets
Run Code Online (Sandbox Code Playgroud)
有多个具有相同SubjectId的多重事件,我想最终得到具有唯一SubjectIds的事件,这是该组中的最新事件.我最终得到以下查询.
var events = from x in
(from e in ctx.Events
.Include("TriggeredBy")
.Include("Targets")
group e by e.SubjectId
into g
select new
{
GroupId = g.Key,
EventsWithSameSubjectId = g,
}
)
select x.EventsWithSameSubjectId
.OrderByDescending(y => y.Created).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
查询编译正常并返回正确的结果集.但包含的属性始终为null.
当我剥离查询以查看eagor加载是否正常工作....
var events = (from e in ctx.Events.OfType<DataNotificationEvent>()
.Include("TriggeredBy")
.Include("Targets")
select e).ToList();
Run Code Online (Sandbox Code Playgroud)
这将返回包含所有包含属性的事件.
这是Linq/EF的已知问题/错误还是有任何办法可以摆脱这个错误.
问候
文森特奥特斯
归档时间: |
|
查看次数: |
3882 次 |
最近记录: |