Я пытаюсь найти простой способ выбрать единственного представителя по обслуживанию клиентов для назначения данному пользователю.У меня есть следующие модели:
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.
Как правильно это сделать?