【发布时间】:2012-01-03 15:18:44
【问题描述】:
我正在尝试找到一种简单的方法来挑选一个客户服务代表来分配给给定的用户。我有以下型号:
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.
正确的做法是什么?
【问题讨论】:
-
此外,我认为 Count(predicate) 在 Linq 中对实体不起作用。看看here(搜索count)
-
@Reniuz Count 应该可以正常工作。
标签: c# linq entity-framework ef-code-first