AutoMapper/AutoMapper.Extensions.ExpressionMapping

Support for `contains` function in odata query

icnocop opened this issue · 4 comments

Hi.

When I try to use an odata query with contains an NotSupportedException is thrown with the message The expression (IIF((([10008].FirstName == null) OrElse False), null, Convert([10008].FirstName.Contains(\"John\"))) == True) is not supported..

I've created a reproducible example here:
TwoProjections.zip

Steps to reproduce:

  1. Open solution in Visual Studio 2017
  2. Restore NuGet packages for solution
  3. Build solution (Debug | Any CPU)
  4. Start both web applications in IIS Express (Set as startup project then Ctrl+F5)
  5. Run all tests.
    The GetPersonBsContains test should fail.
    Note: You may have to close and re-open the solution, and rebuild, for the tests to run.
    Note: The GetPersonBsTop10WithCount test will fail unless you apply the work-around in #10.

.NET Framework 4.6.1
AutoMapper 9.0.0
AutoMapper.Extensions.ExpressionMapping 3.1.0

This example doesn't use Entity Framework.

Thank you.

I would try to narrow this down to where you think AutoMapper.Extensions.ExpressionMapping is failing - download the library and reference it instead of the nuget package - looks like System.NotSupportedException is being thrown by OData not AutoMapper.

Does (IIF((([10008].FirstName == null) OrElse False), null, Convert([10008].FirstName.Contains(\"John\"))) == True) work with OData without using AutoMapper.Extensions.ExpressionMapping?

If you change EnableQuery to [EnableQuery(HandleNullPropagation = Microsoft.AspNet.OData.Query.HandleNullPropagationOption.False)] the GetPersonBsContains test works - I suppose because the filter changes.

BTW there a newer library here implementing the recommendation in #10.

Oh - but you're not using EF. What's your database?

Thank you for the quick reply, debugging suggestion, and indication of the new library.

In the real scenario, the database is using Microsoft's SQL Server, but the error still occurs.

If updatimg ''EnableQuery to[EnableQuery(HandleNullPropagation = Microsoft.AspNet.OData.Query.HandleNullPropagationOption.False)]` fails then you may want to reproduce that error because it works against your repro. From what you're presenting this appears to be an OData restriction - unrelated to AutoMapper.