SqlClient: Bug: Are Spatial Types like Geometry and Geography supported?
I tried to fully switch from System.Data.SqlClient to Microsoft.Data.SqlClient and I am getting a NULL response when calling the DbDataReader.GetFieldType(ordinal) method.
Where, the ordinal corresponds to the index of any of the columns with Data Types (Geography or Spatial) from the database.
To the extent, my tests are failing with the following information below.
The weird thing is, why the System.Data.SqlClient is in the picture of the exception?
I only referenced the Microsoft.Data.SqlClient and have no references at System.Data.SqlClient.
Please advise and thanks.
Stack Trace:
TestBaseRepositorySpatialsCrud
Source: BaseRepositorySpatialsTest.cs line 39
Duration: 959 ms
Message:
Test method RepoDb.IntegrationTests.Types.Spatials.BaseRepositorySpatialsTest.TestBaseRepositorySpatialsCrud threw exception:
System.IO.FileNotFoundException: Could not load file or assembly '_System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a_'. The system cannot find the file specified.
Stack Trace:
RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
TypeNameParser.ResolveType(Assembly assembly, String[] names, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
TypeNameParser.ConstructType(Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
Type.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Boolean throwOnError)
SqlConnection.CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, Boolean fThrow) line 1870
SqlDataReader.GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData) line 2778
SqlDataReader.GetValue(Int32 i) line 2668
lambda_method(Closure , DbDataReader )
DataReader.ToEnumerable[TEntity](DbDataReader reader, IDbConnection connection, IDbTransaction transaction)+MoveNext() line 36
List`1.AddEnumerable(IEnumerable`1 enumerable)
Enumerable.ToList[TSource](IEnumerable`1 source)
EnumerableExtension.AsList[T](IEnumerable`1 value) line 71
DbConnectionExtension.ExecuteQueryInternal[TEntity](IDbConnection connection, String commandText, Object param, Nullable`1 commandType, Nullable`1 commandTimeout, IDbTransaction transaction, Boolean skipCommandArrayParametersCheck) line 324
DbConnectionExtension.QueryInternalBase[TEntity](IDbConnection connection, IEnumerable`1 fields, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 1220
DbConnectionExtension.QueryInternal[TEntity](IDbConnection connection, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 294
DbConnectionExtension.Query[TEntity](IDbConnection connection, QueryGroup where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 246
DbConnectionExtension.Query[TEntity](IDbConnection connection, Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, Int32 cacheItemExpiration, Nullable`1 commandTimeout, IDbTransaction transaction, ICache cache, ITrace trace, IStatementBuilder statementBuilder) line 198
DbRepository`1.Query[TEntity](Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, IDbTransaction transaction) line 97
BaseRepository`2.Query(Expression`1 where, IEnumerable`1 orderBy, Nullable`1 top, String hints, String cacheKey, IDbTransaction transaction) line 64
BaseRepositorySpatialsTest.TestBaseRepositorySpatialsCrud() line 55
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Added a solution to support the claim for Microsoft.Data.SqlClient (issue: https://github.com/dotnet/SqlClient/issues/415) — committed to mikependon/SqlClient by mikependon 4 years ago
You cannot use those types with
Microsoft.Data.SqlClient
, because they build againstSystem.Data.SqlClient
and use types declared there. Only solution is to manually build dotMorten.Microsoft.SqlServer.Types againstMicrosoft.Data.SqlClient
(well, actually with some ugly hacks it is possible for .net framework, but for .net core it is the only way)Ideally Microsoft could fix it by providing more flexible mechanisms to load UDT types
@mikependon In case it helps, EF Core supports SQL Server spatial columns on .NET Core by mapping them to types from the community NTS project
These aren’t the same native SQL Server types exposed on .NET Framework, but a lot of the same functionality is supported. Docs: https://docs.microsoft.com/en-us/ef/core/modeling/spatial