所以,在尝试运行IncludeFilter查询时,我面临一些问题。我的项目是建立在。net 4.5.2和我使用EF6。
我需要的是能够过滤结果,因为使用标准的Include方法只会返回大量的数据。
我得到的错误如下:
{"Unable to cast object of type '<>f__AnonymousType0`2[SQL.Repository.ContractServices,System.Linq.IQueryable`1[System.Collections.Generic.List`1[SQL.Repository.ContractServicesInstallments]]]' to type 'SQL.Repository.ContractServices'."}
我的代码如下:
public async Task<List<ContractServices>> GetAll(FilterDTO filterDTO, long companyID)
{
var listContracts = await context.ContractServices
.IncludeFilter(a => a.ContractServicesInstallments.Where(b => b.DueDate
>= DateTime.Today))
.Where(a => a.companyID == companyID)
.Skip(filterDTO.Skip)
.Take(filterDTO.Take.Value)
.ToListAsync();
return listContracts;
}
如果我用标准的。include运行这个,一切正常。
试试下面的代码。
public async Task<List<ContractServices>> GetAll(FilterDTO filterDTO, long companyID)
{
var listContracts = await context.ContractServices
.IncludeFilter(a => a.ContractServicesInstallments.Where(b => b.DueDate
>= DateTime.Today))
.IncludeFilter(a => a.ContractServicesInstallments.Where(a => a.companyID == companyID))
.Skip(filterDTO.Skip)
.Take(filterDTO.Take.Value)
.ToListAsync();
return listContracts;
}`enter code here`