2012-01-03 5 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が示唆少ない持つ任意の代表者を見つけようとしています。

私の試み:

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. 

それを行うための正しい方法は何ですか?

+0

私はCount(述語)はLinqではエンティティには作用しないと考えています。見てください[ここをクリック](http://msdn.microsoft.com/en-us/library/bb738550.aspx)(カウントの検索) – Reniuz

+0

@ Reeniuz Countは正常に動作するはずです。 –

答えて

5

IEnumerable<Customer>としてCustomersを定義しました。これはEFがモデルの一部として考慮していません。タイプをICollection<Customer>に変更します。

+0

私はそれが本当に簡単な何かでなければならないことを知っていました。それは私のコードを他の誰かによってレビューされる前に、私がSOに投稿するために得るものです:) –

関連する問題