diff --git a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs index 8fd3aa803bd..6a0d0e617e5 100644 --- a/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs +++ b/src/EFCore.SqlServer.NTS/Storage/Internal/SqlServerGeometryTypeMapping.cs @@ -23,7 +23,8 @@ public class SqlServerGeometryTypeMapping : RelationalGeometryTypeMap where TGeometry : Geometry { private static readonly MethodInfo _getSqlBytes - = typeof(SqlDataReader).GetRuntimeMethod(nameof(SqlDataReader.GetSqlBytes), [typeof(int)])!; + = typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.GetFieldValue), [typeof(int)])! + .MakeGenericMethod(typeof(SqlBytes)); private static Action? _sqlDbTypeSetter; private static Action? _udtTypeNameSetter; diff --git a/test/EFCore.SqlServer.Tests/Storage/Internal/SqlServerGeometryTypeMappingTests.cs b/test/EFCore.SqlServer.Tests/Storage/Internal/SqlServerGeometryTypeMappingTests.cs index d478099b788..8a27aedd3e6 100644 --- a/test/EFCore.SqlServer.Tests/Storage/Internal/SqlServerGeometryTypeMappingTests.cs +++ b/test/EFCore.SqlServer.Tests/Storage/Internal/SqlServerGeometryTypeMappingTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Data.Common; +using System.Data.SqlTypes; using NetTopologySuite; using NetTopologySuite.Geometries; @@ -20,6 +22,19 @@ public void GenerateSqlLiteral_works() Assert.Equal("geometry::Parse('POINT (1 2 NULL 3)')", Literal(new Point(new CoordinateM(1, 2, 3)), "geometry")); } + [ConditionalFact] + public void GetDataReaderMethod_works_with_DbDataReader() + { + var mapping = new SqlServerGeometryTypeMapping(NtsGeometryServices.Instance, "geometry"); + var method = mapping.GetDataReaderMethod(); + + Assert.NotNull(method); + Assert.Equal("GetFieldValue", method.Name); + Assert.Equal(typeof(DbDataReader), method.DeclaringType); + Assert.True(method.IsGenericMethod); + Assert.Equal(typeof(SqlBytes), method.GetGenericArguments()[0]); + } + private static string Literal(Geometry value, string storeType) => new SqlServerGeometryTypeMapping(NtsGeometryServices.Instance, storeType) .GenerateSqlLiteral(value);