-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSSQL Spatial: Add EF.Functions.CurveToLine
Provides a workaround for returning CircularString, CompoundCurve, and CurvePolygon instances to the client
- Loading branch information
Showing
6 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/EFCore.SqlServer.NTS/Extensions/SqlServerNetTopologySuiteDbFunctionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using NetTopologySuite.Geometries; | ||
|
||
// ReSharper disable once CheckNamespace | ||
|
||
namespace Microsoft.EntityFrameworkCore; | ||
|
||
/// <summary> | ||
/// Contains extension methods on <see cref="DbFunctions" /> for the Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite library. | ||
/// </summary> | ||
public static class SqlServerNetTopologySuiteDbFunctionsExtensions | ||
{ | ||
/// <summary> | ||
/// Maps to the SQL Server <c>STCurveToLine</c> function which returns a polygonal approximation of an instance that contains circular arc segments. | ||
/// </summary> | ||
/// <param name="_">The <see cref="DbFunctions" /> instance.</param> | ||
/// <param name="geometry">The instance containing circular arc segments.</param> | ||
/// <returns>The polygonal approximation.</returns> | ||
public static Geometry CurveToLine(this DbFunctions _, Geometry geometry) | ||
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(CurveToLine))); | ||
} |
63 changes: 63 additions & 0 deletions
63
....SqlServer.NTS/Query/Internal/SqlServerNetTopologySuiteDbFunctionsMethodCallTranslator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.EntityFrameworkCore.Query.SqlExpressions; | ||
using NetTopologySuite.Geometries; | ||
using ExpressionExtensions = Microsoft.EntityFrameworkCore.Query.ExpressionExtensions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public class SqlServerNetTopologySuiteDbFunctionsMethodCallTranslator : IMethodCallTranslator | ||
{ | ||
private static readonly MethodInfo CurveToLineMethodInfo = typeof(SqlServerNetTopologySuiteDbFunctionsExtensions) | ||
.GetMethod(nameof(SqlServerNetTopologySuiteDbFunctionsExtensions.CurveToLine), new[] { typeof(DbFunctions), typeof(Geometry) })!; | ||
|
||
private readonly IRelationalTypeMappingSource _typeMappingSource; | ||
private readonly ISqlExpressionFactory _sqlExpressionFactory; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public SqlServerNetTopologySuiteDbFunctionsMethodCallTranslator( | ||
IRelationalTypeMappingSource typeMappingSource, | ||
ISqlExpressionFactory sqlExpressionFactory) | ||
{ | ||
_typeMappingSource = typeMappingSource; | ||
_sqlExpressionFactory = sqlExpressionFactory; | ||
} | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
public virtual SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger) | ||
{ | ||
if (method.Equals(CurveToLineMethodInfo)) | ||
{ | ||
return _sqlExpressionFactory.Function( | ||
arguments[1], | ||
"STCurveToLine", | ||
Enumerable.Empty<SqlExpression>(), | ||
nullable: true, | ||
instancePropagatesNullability: true, | ||
argumentsPropagateNullability: Enumerable.Empty<bool>(), | ||
method.ReturnType, | ||
_typeMappingSource.FindMapping( | ||
method.ReturnType, | ||
ExpressionExtensions.InferTypeMapping(arguments[1])!.StoreType)); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters