Linq返回未在父实体中使用的子实体
我的模型中有以下实体Linq返回未在父实体中使用的子实体,linq,entity-framework,Linq,Entity Framework,我的模型中有以下实体 public class Permission { public int ID { get; set; } public Operation Operation { get; set; } } public class Operation { public int ID { get; set; } public string Name { get; set; } } 按照设置存储库的方式,我需要查询OperationRepository
public class Permission
{
public int ID { get; set; }
public Operation Operation { get; set; }
}
public class Operation
{
public int ID { get; set; }
public string Name { get; set; }
}
按照设置存储库的方式,我需要查询OperationRepository以查找权限中未使用的所有操作。My EF Operation Entity具有返回权限的导航属性,作为EntityCollection,如下所示:
public partial class Operation : EntityObject
{
public EntityCollection<Permission> Permissions
{
get; set;
}
}
公共部分类操作:EntityObject
{
公共EntityCollection权限
{
获得;设置;
}
}
my OperationRepository中的方法是:
public IEnumerable<IOperation> FindUnassigned()
{
//query here
}
public IEnumerable findunsigned()
{
//在此查询
}
在导航属性“权限”没有任何元素的情况下,过滤您的操作
.Where(p => p.Permissions.Count() == 0)
…通过.Where(p=>!p.Permissions.Any())
我的天哪,我是个十足的新手!)谢谢杰夫。