开发者

Linq return child entities not used in parent entities

I have the case whereby I have the following entities in my model.

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; } 
} 

The way my repository is set up I need to query the OperationRepository to find all those operations that have not been used in a permission. My EF Operation Entity has a navigation property back to the Permissions as an EntityCollection as below:

public partial class Operation : EntityObject
{
    public EntityCollection<Permission> P开发者_JAVA技巧ermissions
    {
        get; set;
    }
}

The method in my OperationRepository is:

public IEnumerable<IOperation> FindUnassigned()
{
    //query here
}


Filter your Operations where the navigation property `Permissions doesn't have any elements

.Where(p => p.Permissions.Count() == 0)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜