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