So, I'm facing some problems when trying to run an IncludeFilter query. My project is built upon .NET 4.5.2 and I'm using EF6.
What I need is to be able to filter the results because using the standard Include method would just return a huge amount of data.
The error I'm getting is the following:
{"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'."}
My code is the following:
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;
}
If I run this with the standard .Include, everything works fine.