我有一个自引用实体:实体框架自我参照实体查询结果是平的,hiearchical
当我询问这个实体..
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();
。但有没有更好的办法做到这一点?