至于继续this question的时候,我有这样的方法:异常调用ToList()
public IEnumerable<Splitting> Get(Guid companyId, long customerId)
{
CustomerRepository customersRep = new CustomerRepository();
var customers = customersRep.Get(companyId);
return GetQuery().Join(customers,
s => s.CustomerId,
c => c.Id,
(s, c) => new { s, c }).
Where(sc => sc.c.Id == customerId).
Select(sc => sc.s);
}
当我做:
var query=Get(someGuid, someCustomerId);
query.ToList(); //This throws an exception
我得到异常:
Unable to create a constant value of type 'MyProj.Domain.Business.Entities.Company.Customers.Customer'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
这种例外情况如何,我该如何解决?
UPDATE:
GetQuery()
返回Context.CreateObjectSet<T>()
其中T在这种情况下是Splitting
类。
CustomerRepository.Get(companyId)
是:
public IEnumerable<Customer> Get(Guid companyId)
{
return GetQuery().
Where(x => x.CompanyId == companyId).
Where(x => x.IsDeleted == false).
AsEnumerable().
OrderBy(x => x.Name.IsNumeric()).
ThenBy(x => x.Name);
}
什么是'GetQuery()'?你可以显示'GetQuery'和'CustomerRepository.Get'的代码吗? – 2011-06-03 02:28:14
@Alex Aza:我更新了问题。 – Naor 2011-06-03 15:37:30
这与'ToList()'没有任何关系。如果你使用'Count()'或者迭代一个'foreach',你会得到相同的异常。 – 2011-06-03 18:38:32