단일 고객 서비스 담당자를 선택하여 주어진 사용자에게 할당하는 쉬운 방법을 찾으려고합니다. 나는 다음과 같은 모델을 가지고 :하위 엔티티 수가 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; }
}
나는 현재 MaxActiveCustomers
보다 Customers
알 적은이있는 담당자를 찾기 위해 노력하고있다.
내 시도 :
NotSupportedException: The specified type member 'Customers' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
을 할 수있는 올바른 방법은 무엇입니까 :
from r in Representatives
where r.MaxActiveCustomers > r.Customers.Count(c => c.Active)
select r
이 나에게 다음과 같은 예외가 있습니다?
게다가 Count (predicate)가 Linq에서 엔티티로 작동하지 않는다고 생각합니다. 보십시오 [여기] (http://msdn.microsoft.com/en-us/library/bb738550.aspx) (카운트 검색) – Reniuz
@ Reeniuz Count 잘 작동합니다. –