2012-01-03 4 views
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; } 
} 

나는 현재 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 

이 나에게 다음과 같은 예외가 있습니다?

+0

게다가 Count (predicate)가 Linq에서 엔티티로 작동하지 않는다고 생각합니다. 보십시오 [여기] (http://msdn.microsoft.com/en-us/library/bb738550.aspx) (카운트 검색) – Reniuz

+0

@ Reeniuz Count 잘 작동합니다. –

답변

5

IEnumerable<Customer>으로 Customers을 정의했으며 EF는 모델의 일부로 간주하지 않습니다. 유형을 ICollection<Customer>으로 변경하십시오.

+0

나는 그것이 정말 간단해야만한다는 것을 알았다. 그게 내가 다른 사람이 내 코드를 검토하기 전에 게시하기 위해 얻는 것이다. :) –

관련 문제