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 6 months ago • 2 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