0
我试图找到一种简单的方法来挑选出一位客户服务代表来分配给给定的用户。我有以下型号:查找具有少于n个子实体的实体
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.
什么是做了正确的方法是什么?
除此之外,我认为计数(谓词)不会在Linq中对实体起作用。看看[这里](http://msdn.microsoft.com/en-us/library/bb738550.aspx)(搜索计数) – Reniuz 2012-01-03 15:29:00
@Reniuz伯爵应该工作得很好。 – 2012-01-03 17:08:30