开发者

Linq return child entities not used in parent entities

开发者 https://www.devze.com 2023-01-31 09:40 出处:网络
I have the case whereby I have the following entities in my model. public class Permission { public int ID { get; set; }

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

精彩评论

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