【发布时间】:2013-06-19 15:18:44
【问题描述】:
我有一个自引用实体:
当我查询这个实体时..
var query = this._context.DispositionPossibilities
.Where(x => x.AreaID == areaID)
.Where(x => x.IsActive == true);
.. 生成的集合具有从根查询返回的每个项目,然后具有 ParentID 的那些项目在子集合中“重复”(由于导航属性)。
我可以这样做删除它们:
// have to ToArray() first because the child entities will be excluded if I don't..
rValue = query.ToArray();
// trim off the entities at the root that shouldn't be there..
rValue = rValue.Where(x => !x.ParentCode.HasValue).ToArray();
.. 但是有没有更好的方法来做到这一点?
【问题讨论】:
标签: entity-framework self-reference