Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class SqlServerGeometryTypeMapping<TGeometry> : 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<DbParameter, SqlDbType>? _sqlDbTypeSetter;
private static Action<DbParameter, string>? _udtTypeNameSetter;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Geometry>(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<Geometry>(NtsGeometryServices.Instance, storeType)
.GenerateSqlLiteral(value);
Expand Down