You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are trying to implement latest OData in our project. We are using EF Core, and what we are trying to do is, map the domain set to new IQueryable of Dto Models using custom expression function as mapper. After the apply of the OData filters, the query is broken and cannot be executerd.
public static Expression<Func<PurchaseType, PurchaseTypeDto>> ToDto()
{
return domain => new PurchaseTypeDto
{
Id = domain.Id,
Code = domain.Code
};
}
In the controller, we have service call (which returns IQueryable) and we are applying the ODataQueryOptions opts.
[HttpGet]
public async Task<IActionResult> Get(ODataQueryOptions<PurchaseTypeDto> opts)
{
var query =
opts.ApplyTo(_purchaseTypeService.GetAll()) as IQueryable<PurchaseTypeDto>;
var result = await query.ToListAsync();
return Ok(result);
}
InvalidOperationException: The LINQ expression
'DbSet < PurchaseType >
.Where(p => new PurchaseTypeDto {
Id = p.Id,
Code = p.Code
}.Id == __TypedProperty_0)' could not be translated.
The text was updated successfully, but these errors were encountered:
One such function that has to be evaluated client-side is substring - see #20173.
For functions that can't be translated to SQL, is there a plan for the ApplyTo method to handle the ToList/etc. internally? Without parsing the functions ourselves, it's difficult to know if the filter can be evaluated in SQL or in client before we pass it to AppyTo.
We are trying to implement latest OData in our project. We are using EF Core, and what we are trying to do is, map the domain set to new IQueryable of Dto Models using custom expression function as mapper. After the apply of the OData filters, the query is broken and cannot be executerd.
Assemblies affected
Microsoft.AspNetCore.OData v7.3.0
Microsoft.EntityFrameworkCore v3.1.2
.Net Core 3.1 WebApi Project
Reproduce steps
IQueryable that is returned in the controller
Expression function used for mapping
In the controller, we have service call (which returns IQueryable) and we are applying the ODataQueryOptions opts.
Expected result
When the url is accessed https://localhost:44361/odata/PurchaseType?%24filter=Id%20eq%202,
execute the query and result is returned
Actual result
The created query could not be executed
The text was updated successfully, but these errors were encountered: