EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Error when working with NetTopology inside deferred

Open kurthamilton opened this issue 1 year ago • 3 comments

Description

I recently added the Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite to work with the Point data structure, which represents the SQL Server geographic data type.

When I run a single query for an entity containing a Point property, the data is returned as expected.

When I run several queries together using EF+ deferred/future functions, I receive the error below.

Exception

An unhandled exception has occurred while executing the request.
System.IO.FileNotFoundException: 
Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, 
PublicKeyToken=89845dcd8080cc91'.
The system cannot find the file specified.
File name: 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* 
__pAssemblyNameParts_native,
 ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, 
Int32 __throwOnFileNotFound_native, 
ObjectHandleOnStack __assemblyLoadContext_native, 
ObjectHandleOnStack __retAssembly_native)

Example code

// Assume that Address is an entity containing a property with data type NetTopologySuite.Geometries.Point
// These queries would run successfully
var result1 = await Context.Set<Address>().Where(x => x.Id == 123).FirstOrDefaultAsync();
var result2 = await Context.Set<Address>().Where(x => x.Id == 456).FirstOrDefaultAsync();
// However, running as a deferred query will fail
var query1 = Context.Set<Address>().Where(x => x.Id == 123).DeferredSingleOrDefault().FutureValue();
var query2 = Context.Set<Address>().Where(x => x.Id == 456).DeferredSingleOrDefault().FutureValue();

var result1 = await query1.ValueAsync();
var result2 = await query2.ValueAsync();

Stack

  • Z.EntityFramework.Plus.EFCore v8.103.1
  • Microsoft.EntityFrameworkCore.SqlServer v8.0.7
  • Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite v8.0.7
  • MSSqlServer 14 + 16
  • .NET 8

kurthamilton avatar Aug 09 '24 12:08 kurthamilton

Hello @kurthamilton ,

Thank you for reporting.

We will look at it to see if we can quickly fix it.

Best Regards,

Jon

JonathanMagnan avatar Aug 09 '24 13:08 JonathanMagnan

Hello @kurthamilton ,

We are currently getting an error that is different from yours. As we were not expecting an error about Microsoft.SqlServer.Types.

However, even if we find out why you get this error, the feature will still not work. We have some limitations in the way we created this feature. We need to eventually rewrite it to fix those limitations, but that's not currently in our short-term plans.

In short, we indeed have an issue with NetTopology for queries that use the Query Future, but it will not be fixed at this moment.

Best Regards,

Jon

JonathanMagnan avatar Aug 12 '24 16:08 JonathanMagnan

I have been running into this issue since NTS became the default for geospatial data in EF Core years ago. I have had to "downgrade" to a separate standalone query for objects that have geography data types, along with my future queries. Frustrating because I can't use it together with the other future queries it belongs with. I have been waiting patiently for this to be fixed, and I'm hoping that it finally makes its way to the short-term to-do list.

arex388 avatar Oct 21 '24 22:10 arex388