AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

$filter 'not contains' have different behaviour on IEnumerable

Open mferraricloudsurfers opened this issue 6 months ago • 0 comments

Assemblies affected ASP.NET Core OData 9.3.1

Describe the bug I have a SQL Server database with a Customer table. Customer contains a column named CustomerName. I'm processing the following request: api/odata/customer?$filter=not Contains(customerName,'XXX')

Use case 1

[EnableQuery]
public async Task<IActionResult> Get()
{
    return Ok((await GetQuery()).AsNoTracking().ProjectToType<CustomerVM>());
}

This API returns correctly all those customers with CustomerName different from 'XXX'. Null values included!!

Use case 2

public async Task<IActionResult> Get(ODataQueryOptions<CustomerVM> queryOptions)
{
   var tmp = (await GetQuery()).Select(t=>new CustomerVM { customerId = t.CustomerId, customerName = t.Name}).ToList();
   var res = queryOptions.ApplyTo(tmp.AsQueryable());
   return Ok(res);
}

In this case, returns all those customers with CustomerName different from 'XXX' but not returns those with customerName == null.

mferraricloudsurfers avatar May 22 '25 10:05 mferraricloudsurfers