提交 62bdcd1b 编写于 作者: M Marc Gravell

1.33: SqlGeometry (core) and DbGeometry (EF) support

上级 54bc52b3
......@@ -32,5 +32,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -839,11 +839,14 @@ internal static DbType LookupDbType(Type type, string name, out ITypeHandler han
{
return DbType.Object;
}
if(type.FullName == "Microsoft.SqlServer.Types.SqlGeography")
{
handler = new UdtTypeHandler("GEOGRAPHY");
AddTypeHandler(type, handler);
return DbType.Object;
switch (type.FullName)
{
case "Microsoft.SqlServer.Types.SqlGeography":
AddTypeHandler(type, handler = new UdtTypeHandler("GEOGRAPHY"));
return DbType.Object;
case "Microsoft.SqlServer.Types.SqlGeometry":
AddTypeHandler(type, handler = new UdtTypeHandler("GEOMETRY"));
return DbType.Object;
}
throw new NotSupportedException(string.Format("The member {0} of type {1} cannot be used as a parameter value", name, type));
}
......
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -57,10 +57,15 @@
<Compile Include="..\Dapper.EntityFramework NET45\DbGeographyHandler.cs">
<Link>DbGeographyHandler.cs</Link>
</Compile>
<Compile Include="..\Dapper.EntityFramework NET45\DbGeometryHandler.cs">
<Link>DbGeometryHandler.cs</Link>
</Compile>
<Compile Include="..\Dapper.EntityFramework NET45\Handlers.cs">
<Link>Handlers.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\Dapper.EntityFramework NET45\Properties\AssemblyInfo.cs">
<Link>AssemblyInfo.cs</Link>
</Compile>
<Compile Include="SqlServerTypes\Loader.cs" />
</ItemGroup>
<ItemGroup>
......@@ -92,6 +97,9 @@
<Name>Dapper NET40</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Dapper.EntityFramework NET40")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dapper.EntityFramework NET40")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("85331b38-d6e0-41f6-b1ed-b27a8747f827")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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")]
......@@ -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" />
......
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 class Handlers
public static void Register()
{
SqlMapper.AddTypeHandler(DbGeographyHandler.Default);
SqlMapper.AddTypeHandler(DbGeometryHandler.Default);
}
}
}
......@@ -31,6 +31,5 @@
//
// 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")]
......@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2">
<id>Dapper.EntityFramework</id>
<version>1.26</version>
<version>1.33</version>
<title>Dapper entity framework type handlers</title>
<authors>Marc Gravell</authors>
<owners>Marc Gravell</owners>
......@@ -14,7 +14,7 @@
<tags>orm sql micro-orm</tags>
<dependencies>
<dependency id="EntityFramework" version="6.1.1" />
<dependency id="Dapper" version="1.26" />
<dependency id="Dapper" version="1.33" />
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Core"/>
......
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.32.0.0")]
[assembly: AssemblyFileVersion("1.32.0.0")]
[assembly: AssemblyVersion("1.33.0.0")]
[assembly: AssemblyFileVersion("1.33.0.0")]
......@@ -2986,45 +2986,51 @@ class HazGeo
{
public int Id { get; set; }
public DbGeography Geo { get; set; }
public DbGeometry Geometry { get; set; }
}
class HazSqlGeo
{
public int Id { get; set; }
public SqlGeography Geo { get; set; }
public SqlGeometry Geometry { get; set; }
}
public void DBGeography_SO24405645_SO24402424()
{
Dapper.EntityFramework.Handlers.Register();
connection.Execute("create table #Geo (id int, geo geography)");
connection.Execute("create table #Geo (id int, geo geography, geometry geometry)");
var obj = new HazGeo
{
Id = 1,
Geo = DbGeography.LineFromText("LINESTRING(-122.360 47.656, -122.343 47.656 )", 4326)
Geo = DbGeography.LineFromText("LINESTRING(-122.360 47.656, -122.343 47.656 )", 4326),
Geometry = DbGeometry.LineFromText("LINESTRING (100 100, 20 180, 180 180)", 0)
};
connection.Execute("insert #Geo(id, geo) values (@Id, @Geo)", obj);
connection.Execute("insert #Geo(id, geo, geometry) values (@Id, @Geo, @Geometry)", obj);
var row = connection.Query<HazGeo>("select * from #Geo where id=1").SingleOrDefault();
row.IsNotNull();
row.Id.IsEqualTo(1);
row.Geo.IsNotNull();
row.Geometry.IsNotNull();
}
public void SqlGeography_SO25538154()
{
Dapper.SqlMapper.ResetTypeHandlers();
connection.Execute("create table #SqlGeo (id int, geo geography)");
connection.Execute("create table #SqlGeo (id int, geo geography, geometry geometry)");
var obj = new HazSqlGeo
{
Id = 1,
Geo = SqlGeography.STLineFromText(new SqlChars(new SqlString("LINESTRING(-122.360 47.656, -122.343 47.656 )")), 4326)
Geo = SqlGeography.STLineFromText(new SqlChars(new SqlString("LINESTRING(-122.360 47.656, -122.343 47.656 )")), 4326),
Geometry = SqlGeometry.STLineFromText(new SqlChars(new SqlString("LINESTRING (100 100, 20 180, 180 180)")), 0)
};
connection.Execute("insert #SqlGeo(id, geo) values (@Id, @Geo)", obj);
connection.Execute("insert #SqlGeo(id, geo, geometry) values (@Id, @Geo, @Geometry)", obj);
var row = connection.Query<HazSqlGeo>("select * from #SqlGeo where id=1").SingleOrDefault();
row.IsNotNull();
row.Id.IsEqualTo(1);
row.Geo.IsNotNull();
row.Geometry.IsNotNull();
}
public void TypeBasedViaDynamic()
......
......@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2">
<id>Dapper</id>
<version>1.32</version>
<version>1.33</version>
<title>Dapper dot net</title>
<authors>Sam Saffron,Marc Gravell</authors>
<owners>Sam Saffron,Marc Gravell</owners>
......@@ -19,6 +19,7 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.0-Client, .NETFramework4.0" />
</frameworkAssemblies>
<releaseNotes>
* 1.33 - Support for SqlGeometry (core) and DbGeometry (EF)
* 1.32 - Support for SqlGeography in core library
* 1.31 - Fix issue with error message when there is a column/type mismatch
* 1.30 - Better async cancellation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册