dotMorten.Microsoft.SqlServer.Types 2.4.0

Microsoft.SqlServer.Types

a .NET Standard implementation of the spatial types in Microsoft.SqlServer.Types.

Difference between v1.x and v2.x

The v1.x and v2.x versions are identical and kept in sync. The only difference is the dependency:

  • v1.x : Depends on the legacy System.Data.SqlClient package.
  • v2.x : Depends on updated Microsoft.Data.SqlClient package.

Examples

Input parameter

Assigning SqlGeometry or SqlGeography to a command parameter:

   command.Parameters.AddWithValue("@GeographyColumn", mySqlGeography);
   command.Parameters["@GeometryColumn"].UdtTypeName = "Geography";

   command.Parameters.AddWithValue("@GeographyColumn", mySqlGeometry);
   command.Parameters["@GeometryColumn"].UdtTypeName = "Geometry" 

The geometry will automatically be correctly serialized.

Reading geometry and geography

Use the common methods for getting fields of specific types:

   var geom1 = reader.GetValue(geomColumn) as SqlGeometry;
   var geom2 = reader.GetFieldValue<SqlGeometry>(geomColumn);
   var geom3 = SqlGeometry.Deserialize(reader.GetSqlBytes(geomColumn)); //Avoids any potential assembly-redirect issue. See https://docs.microsoft.com/en-us/sql/sql-server/install/warning-about-client-side-usage-of-geometry-geography-and-hierarchyid?view=sql-server-2014#corrective-action

Notes:

The spatial operations like intersection, area etc are not included here. You can perform these as part of your query instead and get them returned in a column.

Showing the top 20 packages that depend on dotMorten.Microsoft.SqlServer.Types.

Packages Downloads
EFCore.BulkExtensions
EntityFramework EF Core Bulk Batch Extensions for Insert Update Delete and Read (CRUD) operations on SQL Server and SQLite
4
EntityFrameworkCore.SqlServer.HierarchyId.Abstractions
Adds hierarchyid support to the SQL Server EF Core provider
3
EntityFrameworkCore.SqlServer.HierarchyId.Abstractions
Adds hierarchyid support to the SQL Server EF Core provider
4
EntityFrameworkCore.SqlServer.HierarchyId.Abstractions
Common abstractions for using hierarchyid with EF Core
4

.NET Standard 2.0

Version Downloads Last updated
2.4.0 2 06/02/2024
1.5.0 2 06/13/2023
1.4.0 2 06/02/2024
1.3.0 3 03/11/2024
1.2.0 1 06/02/2024
1.1.0 3 06/02/2024