zzzprojects / EntityFramework-Plus

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
https://entityframework-plus.net/
MIT License
2.27k stars 318 forks source link

using geometry type in queryable object result to raise this exception: No mapping exists from object type NetTopologySuite.Geometries.Polygon to a known managed provider native type. #704

Closed amirmostaghim closed 2 years ago

amirmostaghim commented 3 years ago

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

Hello everyone, I'm using some conditions in my quaryable object and everything ok until I added a geometry type column in quaryable object condition and result to internal error server

2. Exception

ERROR 2021-10-19 01:00:50,680 [55 ] Mvc.ExceptionHandling.AbpExceptionFilter - No mapping exists from object type NetTopologySuite.Geometries.Polygon to a known managed provider native type.

Exception message:
Stack trace:
System.ArgumentException: No mapping exists from object type NetTopologySuite.Geometries.Polygon to a known managed provider native type.
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__169_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Z.EntityFramework.Plus.QueryFutureBatch.ExecuteQueriesAsync(CancellationToken cancellationToken)
   at Z.EntityFramework.Plus.QueryFutureValue`1.ValueAsync(CancellationToken cancellationToken)
   at SnapTaxi.EfRepository.People.PeopleManager.GetPeopleAndContactCount(PeopleDateFilterDtoQuery request, List`1 filters, List`1 sorts) in C:\Users\Amir\RiderProjects\SnapTaxi\src\SnapTaxi.EfRepository\People\PeopleManager.cs:line 235
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at SnapTaxi.Peoples.Queries.GetNumberOfPeoplesAndContactsDtoQueryHandler.Handle(GetNumberOfPeoplesAndContactsDtoQuery request, CancellationToken cancellationToken) in C:\Users\Amir\RiderProjects\SnapTaxi\src\SnapTaxi.Application\Peoples\Queries\GetNumberOfPeoplesAndContactsDtoQueryHandler.cs:line 29
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at SnapTaxi.Peoples.PeoplesAppService.GetNumberOfPeoplesAndContacts(GetNumberOfPeoplesAndContactsDtoQuery getNumberOfContactsDtoQuery) in C:\Users\Amir\RiderProjects\SnapTaxi\src\SnapTaxi.Application\Peoples\PeoplesAppService.cs:line 81
   at lambda_method1891(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

4. Any further technical details

this my code snippet:


        public async Task<(int PeopleCount, int contactCount)> GetPeopleAndContactCount(
            ConversationDateFilterDtoQuery request, List<Filter> filters = null, List<Sort> sorts = null)
        {
            var queryable = await GetQueryable(request, false);
            queryable = queryable.ApplyFilters(filters);
            queryable = ApplyPolygons(queryable, request.Polygons);
            var peopleCount = queryable.DeferredCount().FutureValue();
            var contactCount = queryable.Select(p => p.ContactId).Distinct().DeferredCount().FutureValue();

            return (await peopleCount .ValueAsync(), await contactCount.ValueAsync());
        }

and this my my ApplyPolygon method:

        private static IQueryable<People> ApplyPolygons(IQueryable<People> queryable,List<Polygon> polygons )
        {
            if (polygons == null || !polygons.Any())
            {
                return queryable;
            }

            var expression = PredicateBuilder.New<People>();
            foreach (var geometry in polygons)
            {
                expression.Or(people=> People.Location.Intersects(geometry));
            }

            return queryable.Where(expression);
        }    
JonathanMagnan commented 3 years ago

Hello @amirmostaghim ,

Thank you for reporting,

We will look if that's possible to support it on our side.

Best Regards,

Jon


Sponsorship Help us improve this library

Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan commented 2 years ago

Hello @amirmostaghim ,

A new version has been released.

Could you try the latest version and let us know if everything has been fixed correctly?

Best Regards,

Jon


Is this library useful to you? Please help us by becoming a sponsor to keep it alive and supported.