找不到n sub-entities实体

本文关键字:实体 sub-entities 找不到 | 更新日期: 2023-09-27 18:19:15

我试图找到一种简单的方法来挑选单个客户服务代表来分配给给定的用户。我有以下型号:

public class Customer
{
    public int Id { get; set; }
    // SNIP
    public virtual Representative Representative { get; set; }
    public bool Active { get; set; }
}
public class Representative
{
    public int Id { get; set; }
    public int MaxActiveCustomers { get; set; }
    // all the customers this representative has interacted with
    public IEnumerable<Customer> Customers { get; set; }
}

我正在寻找目前Customers少于MaxActiveCustomers建议的任何代表。

我的尝试:

from r in Representatives
where r.MaxActiveCustomers > r.Customers.Count(c => c.Active)
select r

这给了我下面的异常:

NotSupportedException: The specified type member 'Customers' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

正确的做法是什么?

找不到n sub-entities实体

您已经将Customers定义为IEnumerable<Customer>类型,EF不将其视为模型的一部分。将字体改为ICollection<Customer>