mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-27 03:27:02 +08:00
1.33: SqlGeometry (core) and DbGeometry (EF) support
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DbGeometryHandler.cs" />
|
||||
<Compile Include="DbGeographyHandler.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Handlers.cs" />
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.SqlServer.Types;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Entity.Spatial;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace Dapper.EntityFramework
|
||||
{
|
||||
/// <summary>
|
||||
/// Type-handler for the DbGeometry spatial type
|
||||
/// </summary>
|
||||
public class DbGeometryHandler : Dapper.SqlMapper.TypeHandler<DbGeometry>
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new handler instance
|
||||
/// </summary>
|
||||
protected DbGeometryHandler() { }
|
||||
/// <summary>
|
||||
/// Default handler instance
|
||||
/// </summary>
|
||||
public static readonly DbGeometryHandler Default = new DbGeometryHandler();
|
||||
/// <summary>
|
||||
/// Assign the value of a parameter before a command executes
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to configure</param>
|
||||
/// <param name="value">Parameter value</param>
|
||||
public override void SetValue(IDbDataParameter parameter, DbGeometry value)
|
||||
{
|
||||
parameter.Value = value == null ? (object)DBNull.Value : (object)SqlGeometry.Parse(value.AsText());
|
||||
if (parameter is SqlParameter)
|
||||
{
|
||||
((SqlParameter)parameter).UdtTypeName = "GEOMETRY";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Parse a database value back to a typed value
|
||||
/// </summary>
|
||||
/// <param name="value">The value from the database</param>
|
||||
/// <returns>The typed value</returns>
|
||||
public override DbGeometry Parse(object value)
|
||||
{
|
||||
return (value == null || value is DBNull) ? null : DbGeometry.FromText(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
public static void Register()
|
||||
{
|
||||
SqlMapper.AddTypeHandler(DbGeographyHandler.Default);
|
||||
SqlMapper.AddTypeHandler(DbGeometryHandler.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,5 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
Reference in New Issue
Block a user