Commit ccc189c2 authored by James Holwell's avatar James Holwell

Merge remote-tracking branch 'upstream/master' into arbitrary-multi-maps

Conflicts:
	Dapper NET45/SqlMapperAsync.cs
parents 3b0fd2d0 5472d2ab
...@@ -32,5 +32,5 @@ ...@@ -32,5 +32,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
This diff is collapsed.
This diff is collapsed.
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
...@@ -57,10 +57,15 @@ ...@@ -57,10 +57,15 @@
<Compile Include="..\Dapper.EntityFramework NET45\DbGeographyHandler.cs"> <Compile Include="..\Dapper.EntityFramework NET45\DbGeographyHandler.cs">
<Link>DbGeographyHandler.cs</Link> <Link>DbGeographyHandler.cs</Link>
</Compile> </Compile>
<Compile Include="..\Dapper.EntityFramework NET45\DbGeometryHandler.cs">
<Link>DbGeometryHandler.cs</Link>
</Compile>
<Compile Include="..\Dapper.EntityFramework NET45\Handlers.cs"> <Compile Include="..\Dapper.EntityFramework NET45\Handlers.cs">
<Link>Handlers.cs</Link> <Link>Handlers.cs</Link>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="..\Dapper.EntityFramework NET45\Properties\AssemblyInfo.cs">
<Link>AssemblyInfo.cs</Link>
</Compile>
<Compile Include="SqlServerTypes\Loader.cs" /> <Compile Include="SqlServerTypes\Loader.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -92,6 +97,9 @@ ...@@ -92,6 +97,9 @@
<Name>Dapper NET40</Name> <Name>Dapper NET40</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. 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 @@ ...@@ -52,6 +52,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DbGeometryHandler.cs" />
<Compile Include="DbGeographyHandler.cs" /> <Compile Include="DbGeographyHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Handlers.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 ...@@ -11,6 +11,7 @@ public static class Handlers
public static void Register() public static void Register()
{ {
SqlMapper.AddTypeHandler(DbGeographyHandler.Default); SqlMapper.AddTypeHandler(DbGeographyHandler.Default);
SqlMapper.AddTypeHandler(DbGeometryHandler.Default);
} }
} }
} }
...@@ -31,6 +31,5 @@ ...@@ -31,6 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2"> <metadata schemaVersion="2">
<id>Dapper.EntityFramework</id> <id>Dapper.EntityFramework</id>
<version>1.26</version> <version>1.33</version>
<title>Dapper entity framework type handlers</title> <title>Dapper entity framework type handlers</title>
<authors>Marc Gravell</authors> <authors>Marc Gravell</authors>
<owners>Marc Gravell</owners> <owners>Marc Gravell</owners>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<tags>orm sql micro-orm</tags> <tags>orm sql micro-orm</tags>
<dependencies> <dependencies>
<dependency id="EntityFramework" version="6.1.1" /> <dependency id="EntityFramework" version="6.1.1" />
<dependency id="Dapper" version="1.26" /> <dependency id="Dapper" version="1.33" />
</dependencies> </dependencies>
<frameworkAssemblies> <frameworkAssemblies>
<frameworkAssembly assemblyName="System.Core"/> <frameworkAssembly assemblyName="System.Core"/>
......
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
...@@ -17,9 +17,17 @@ public void TestBasicStringUsage() ...@@ -17,9 +17,17 @@ public void TestBasicStringUsage()
} }
public void TestClassWithStringUsage() public void TestClassWithStringUsage()
{ {
var oldMatch = Dapper.DefaultTypeMap.MatchNamesWithUnderscores;
try
{
DefaultTypeMap.MatchNamesWithUnderscores = true;
var arr = connection.Query<BasicType>("select 'abc' as [Value], '123' as [Another_Value] union all select @txt, @txt2", new { txt = "def", txt2 = "456" }).ToArray(); var arr = connection.Query<BasicType>("select 'abc' as [Value], '123' as [Another_Value] union all select @txt, @txt2", new { txt = "def", txt2 = "456" }).ToArray();
arr.Select(x => x.Value).IsSequenceEqualTo(new[] { "abc", "def" }); arr.Select(x => x.Value).IsSequenceEqualTo(new[] { "abc", "def" });
arr.Select(x => x.AnotherValue).IsSequenceEqualTo(new[] { "123", "456" }); arr.Select(x => x.AnotherValue).IsSequenceEqualTo(new[] { "123", "456" });
} finally
{
DefaultTypeMap.MatchNamesWithUnderscores = oldMatch;
}
} }
class BasicType class BasicType
{ {
......
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System; using System;
using System.Threading.Tasks;
using System.Threading;
using System.Data.SqlClient;
namespace DapperTests_NET45 namespace DapperTests_NET45
{ {
...@@ -18,6 +21,35 @@ public void TestBasicStringUsageAsync() ...@@ -18,6 +21,35 @@ public void TestBasicStringUsageAsync()
arr.IsSequenceEqualTo(new[] { "abc", "def" }); arr.IsSequenceEqualTo(new[] { "abc", "def" });
} }
} }
public void TestBasicStringUsageAsyncNonBuffered()
{
using (var connection = Program.GetOpenConnection())
{
var query = connection.QueryAsync<string>(new CommandDefinition("select 'abc' as [Value] union all select @txt", new { txt = "def" }, flags: CommandFlags.None));
var arr = query.Result.ToArray();
arr.IsSequenceEqualTo(new[] { "abc", "def" });
}
}
public void TestLongOperationWithCancellation()
{
using(var connection = Program.GetClosedConnection())
{
CancellationTokenSource cancel = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var task = connection.QueryAsync<int>(new CommandDefinition("waitfor delay '00:00:10';select 1", cancellationToken: cancel.Token));
try
{
if (!task.Wait(TimeSpan.FromSeconds(7)))
{
throw new TimeoutException(); // should have cancelled
}
}
catch (AggregateException agg)
{
(agg.InnerException is SqlException).IsTrue();
}
}
}
public void TestBasicStringUsageClosedAsync() public void TestBasicStringUsageClosedAsync()
{ {
...@@ -29,6 +61,16 @@ public void TestBasicStringUsageClosedAsync() ...@@ -29,6 +61,16 @@ public void TestBasicStringUsageClosedAsync()
} }
} }
public void TestQueryDynamicAsync()
{
using (var connection = Program.GetClosedConnection())
{
var row = connection.QueryAsync("select 'abc' as [Value]").Result.Single();
string value = row.Value;
value.IsEqualTo("abc");
}
}
public void TestClassWithStringUsageAsync() public void TestClassWithStringUsageAsync()
{ {
using (var connection = Program.GetOpenConnection()) using (var connection = Program.GetOpenConnection())
...@@ -122,8 +164,8 @@ public void TestMultiAsync() ...@@ -122,8 +164,8 @@ public void TestMultiAsync()
{ {
using (Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result) using (Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result)
{ {
multi.Read<int>().Single().IsEqualTo(1); multi.ReadAsync<int>().Result.Single().IsEqualTo(1);
multi.Read<int>().Single().IsEqualTo(2); multi.ReadAsync<int>().Result.Single().IsEqualTo(2);
} }
} }
} }
...@@ -133,8 +175,8 @@ public void TestMultiClosedConnAsync() ...@@ -133,8 +175,8 @@ public void TestMultiClosedConnAsync()
{ {
using (Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result) using (Dapper.SqlMapper.GridReader multi = conn.QueryMultipleAsync("select 1; select 2").Result)
{ {
multi.Read<int>().Single().IsEqualTo(1); multi.ReadAsync<int>().Result.Single().IsEqualTo(1);
multi.Read<int>().Single().IsEqualTo(2); multi.ReadAsync<int>().Result.Single().IsEqualTo(2);
} }
} }
} }
......
...@@ -72,6 +72,10 @@ ...@@ -72,6 +72,10 @@
<Reference Include="LinFu.DynamicProxy"> <Reference Include="LinFu.DynamicProxy">
<HintPath>NHibernate\LinFu.DynamicProxy.dll</HintPath> <HintPath>NHibernate\LinFu.DynamicProxy.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.SqlServer.Types.11.0.1\lib\net20\Microsoft.SqlServer.Types.dll</HintPath>
</Reference>
<Reference Include="Mono.Security"> <Reference Include="Mono.Security">
<HintPath>..\packages\Npgsql.2.0.11\lib\Net40\Mono.Security.dll</HintPath> <HintPath>..\packages\Npgsql.2.0.11\lib\Net40\Mono.Security.dll</HintPath>
</Reference> </Reference>
...@@ -165,6 +169,7 @@ ...@@ -165,6 +169,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
</Compile> </Compile>
<Compile Include="SqlServerTypes\Loader.cs" />
<Compile Include="SubSonic\ActiveRecord.cs"> <Compile Include="SubSonic\ActiveRecord.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
...@@ -228,6 +233,22 @@ ...@@ -228,6 +233,22 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="..\packages\Microsoft.SqlServer.Types.11.0.1\nativeBinaries\x64\msvcr100.dll">
<Link>SqlServerTypes\x64\msvcr100.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\packages\Microsoft.SqlServer.Types.11.0.1\nativeBinaries\x64\SqlServerSpatial110.dll">
<Link>SqlServerTypes\x64\SqlServerSpatial110.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\packages\Microsoft.SqlServer.Types.11.0.1\nativeBinaries\x86\msvcr100.dll">
<Link>SqlServerTypes\x86\msvcr100.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\packages\Microsoft.SqlServer.Types.11.0.1\nativeBinaries\x86\SqlServerSpatial110.dll">
<Link>SqlServerTypes\x86\SqlServerSpatial110.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="NHibernate\hibernate.cfg.xml" /> <Content Include="NHibernate\hibernate.cfg.xml" />
<Content Include="NHibernate\Post.hbm.xml" /> <Content Include="NHibernate\Post.hbm.xml" />
<Content Include="OrmLite\ServiceStack.Common.dll" /> <Content Include="OrmLite\ServiceStack.Common.dll" />
...@@ -238,6 +259,7 @@ ...@@ -238,6 +259,7 @@
<Content Include="Soma\Soma.Core.dll" /> <Content Include="Soma\Soma.Core.dll" />
<Content Include="Soma\Soma.Core.IT.MsSql.dll" /> <Content Include="Soma\Soma.Core.IT.MsSql.dll" />
<Content Include="Soma\Soma.Core.IT.MsSqlCe.dll" /> <Content Include="Soma\Soma.Core.IT.MsSqlCe.dll" />
<Content Include="SqlServerTypes\readme.htm" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="bltoolkit\" /> <Folder Include="bltoolkit\" />
......
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.28.0.0")] [assembly: AssemblyVersion("1.34.0.0")]
[assembly: AssemblyFileVersion("1.28.0.0")] [assembly: AssemblyFileVersion("1.34.0.0")]
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace SqlServerTypes
{
/// <summary>
/// Utility methods related to CLR Types for SQL Server
/// </summary>
internal class Utilities
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadLibrary(string libname);
/// <summary>
/// Loads the required native assemblies for the current architecture (x86 or x64)
/// </summary>
/// <param name="rootApplicationPath">
/// Root path of the current application. Use Server.MapPath(".") for ASP.NET applications
/// and AppDomain.CurrentDomain.BaseDirectory for desktop applications.
/// </param>
public static void LoadNativeAssemblies(string rootApplicationPath)
{
var nativeBinaryPath = IntPtr.Size > 4
? Path.Combine(rootApplicationPath, @"SqlServerTypes\x64\")
: Path.Combine(rootApplicationPath, @"SqlServerTypes\x86\");
LoadNativeAssembly(nativeBinaryPath, "msvcr100.dll");
LoadNativeAssembly(nativeBinaryPath, "SqlServerSpatial110.dll");
}
private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
{
var path = Path.Combine(nativeBinaryPath, assemblyName);
var ptr = LoadLibrary(path);
if (ptr == IntPtr.Zero)
{
throw new Exception(string.Format(
"Error loading {0} (ErrorCode: {1})",
assemblyName,
Marshal.GetLastWin32Error()));
}
}
}
}
\ No newline at end of file
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>Microsoft.SqlServer.Types</title>
<style>
body {
background: #fff;
color: #505050;
margin: 20px;
}
#main {
background: #efefef;
padding: 5px 30px;
}
</style>
</head>
<body>
<div id="main">
<h1>Action required to load native assemblies</h1>
<p>
To deploy an application that uses spatial data types to a machine that does not have 'System CLR Types for SQL Server' installed you also need to deploy the native assembly SqlServerSpatial110.dll. Both x86 (32 bit) and x64 (64 bit) versions of this assembly have been added to your project under the SqlServerTypes\x86 and SqlServerTypes\x64 subdirectories. The native assembly msvcr100.dll is also included in case the C++ runtime is not installed.
</p>
<p>
You need to add code to load the correct one of these assemblies at runtime (depending on the current architecture).
</p>
<h2>ASP.NET applications</h2>
<p>
For ASP.NET applications, add the following line of code to the Application_Start method in Global.asax.cs:
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));</pre>
</p>
<h2>Desktop applications</h2>
<p>
For desktop applications, add the following line of code to run before any spatial operations are performed:
<pre> SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);</pre>
</p>
</div>
</body>
</html>
\ No newline at end of file
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
using System.Data.Entity.Spatial; using System.Data.Entity.Spatial;
using Microsoft.SqlServer.Types;
using System.Data.SqlTypes;
#if POSTGRESQL #if POSTGRESQL
using Npgsql; using Npgsql;
#endif #endif
...@@ -2676,7 +2678,7 @@ public void TestNullFromInt_NoRows() ...@@ -2676,7 +2678,7 @@ public void TestNullFromInt_NoRows()
public void TestChangingDefaultStringTypeMappingToAnsiString() public void TestChangingDefaultStringTypeMappingToAnsiString()
{ {
var sql = "SELECT SQL_VARIANT_PROPERTY(CONVERT(sql_variant, @testParam),'BaseType') AS BaseType"; var sql = "SELECT SQL_VARIANT_PROPERTY(CONVERT(sql_variant, @testParam),'BaseType') AS BaseType";
var param = new {testParam = "TestString"}; var param = new { testParam = "TestString" };
var result01 = connection.Query<string>(sql, param).FirstOrDefault(); var result01 = connection.Query<string>(sql, param).FirstOrDefault();
result01.IsEqualTo("nvarchar"); result01.IsEqualTo("nvarchar");
...@@ -3011,7 +3013,7 @@ public void DataTableParameters() ...@@ -3011,7 +3013,7 @@ public void DataTableParameters()
{ {
connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter() }).First(); connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter() }).First();
throw new InvalidOperationException(); throw new InvalidOperationException();
} catch(Exception ex) } catch (Exception ex)
{ {
ex.Message.Equals("The table type parameter 'ids' must have a valid type name."); ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
} }
...@@ -3080,25 +3082,70 @@ public void GuidIn_SO_24177902() ...@@ -3080,25 +3082,70 @@ public void GuidIn_SO_24177902()
class HazGeo class HazGeo
{ {
public int Id { get;set; } public int Id { get; set; }
public DbGeography Geo { 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() public void DBGeography_SO24405645_SO24402424()
{ {
Dapper.EntityFramework.Handlers.Register(); 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 var obj = new HazGeo
{ {
Id = 1, 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(); var row = connection.Query<HazGeo>("select * from #Geo where id=1").SingleOrDefault();
row.IsNotNull(); row.IsNotNull();
row.Id.IsEqualTo(1); row.Id.IsEqualTo(1);
row.Geo.IsNotNull(); row.Geo.IsNotNull();
row.Geometry.IsNotNull();
}
public void SqlGeography_SO25538154()
{
Dapper.SqlMapper.ResetTypeHandlers();
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),
Geometry = SqlGeometry.STLineFromText(new SqlChars(new SqlString("LINESTRING (100 100, 20 180, 180 180)")), 0)
};
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 SqlHierarchyId_SO18888911()
{
Dapper.SqlMapper.ResetTypeHandlers();
var row = connection.Query<HazSqlHierarchy>("select 3 as [Id], hierarchyid::Parse('/1/2/3/') as [Path]").Single();
row.Id.Equals(3);
row.Path.IsNotNull();
var val = connection.Query<SqlHierarchyId>("select @Path", row).Single();
val.IsNotNull();
}
public class HazSqlHierarchy
{
public int Id { get; set; }
public SqlHierarchyId Path { get; set; }
} }
public void TypeBasedViaDynamic() public void TypeBasedViaDynamic()
...@@ -3129,7 +3176,7 @@ public void TypeBasedViaTypeMulti() ...@@ -3129,7 +3176,7 @@ public void TypeBasedViaTypeMulti()
Type type = GetSomeType(); Type type = GetSomeType();
dynamic first, second; dynamic first, second;
using(var multi = connection.QueryMultiple("select @A as [A], @B as [B]; select @C as [A], @D as [B]", using (var multi = connection.QueryMultiple("select @A as [A], @B as [B]; select @C as [A], @D as [B]",
new { A = 123, B = "abc", C = 456, D = "def" })) new { A = 123, B = "abc", C = 456, D = "def" }))
{ {
first = multi.Read(type).Single(); first = multi.Read(type).Single();
...@@ -3157,14 +3204,14 @@ static Type GetSomeType() ...@@ -3157,14 +3204,14 @@ static Type GetSomeType()
} }
public class SomeType public class SomeType
{ {
public int A { get;set; } public int A { get; set; }
public string B { get;set; } public string B { get; set; }
} }
class WithInit : ISupportInitialize class WithInit : ISupportInitialize
{ {
public string Value { get; set; } public string Value { get; set; }
public int Flags { get;set; } public int Flags { get; set; }
void ISupportInitialize.BeginInit() void ISupportInitialize.BeginInit()
{ {
...@@ -3450,7 +3497,7 @@ public void TestBigIntForEverythingWorks_SqlLite() ...@@ -3450,7 +3497,7 @@ public void TestBigIntForEverythingWorks_SqlLite()
} }
private void TestBigIntForEverythingWorks_SqlLite_ByDataType<T>(string dbType) private void TestBigIntForEverythingWorks_SqlLite_ByDataType<T>(string dbType)
{ {
using(var reader = connection.ExecuteReader("select cast(1 as " + dbType + ")")) using (var reader = connection.ExecuteReader("select cast(1 as " + dbType + ")"))
{ {
reader.Read().IsTrue(); reader.Read().IsTrue();
reader.GetFieldType(0).Equals(typeof(T)); reader.GetFieldType(0).Equals(typeof(T));
...@@ -3561,6 +3608,64 @@ private void TestBigIntForEverythingWorks<T>(T expected, string dbType) ...@@ -3561,6 +3608,64 @@ private void TestBigIntForEverythingWorks<T>(T expected, string dbType)
} }
public void SO25069578_DynamicParams_Procs()
{
var parameters = new DynamicParameters();
parameters.Add("foo", "bar");
// parameters = new DynamicParameters(parameters);
try { connection.Execute("drop proc SO25069578"); } catch { }
connection.Execute("create proc SO25069578 @foo nvarchar(max) as select @foo as [X]");
var tran = connection.BeginTransaction(); // gist used transaction; behaves the same either way, though
var row = connection.Query<HazX>("SO25069578", parameters,
commandType: CommandType.StoredProcedure, transaction: tran).Single();
tran.Rollback();
row.X.IsEqualTo("bar");
}
public void Issue149_TypeMismatch_SequentialAccess()
{
string error;
Guid guid = Guid.Parse("cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e");
try
{
var result = connection.Query<Issue149_Person>(@"select @guid as Id", new { guid }).First();
error = null;
} catch(Exception ex)
{
error = ex.Message;
}
error.IsEqualTo("Error parsing column 0 (Id=cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e - Object)");
}
public class Issue149_Person { public string Id { get; set; } }
public class HazX
{
public string X { get; set; }
}
public void SO25297173_DynamicIn()
{
var query = @"
declare @table table(value int not null);
insert @table values(1);
insert @table values(2);
insert @table values(3);
insert @table values(4);
insert @table values(5);
insert @table values(6);
insert @table values(7);
SELECT value FROM @table WHERE value IN @myIds";
var queryParams = new Dictionary<string, object> {
{ "myIds", new [] { 5, 6 } }
};
var dynamicParams = new DynamicParameters(queryParams);
List<int> result = connection.Query<int>(query, dynamicParams).ToList();
result.Count.IsEqualTo(2);
result.Contains(5).IsTrue();
result.Contains(6).IsTrue();
}
#if POSTGRESQL #if POSTGRESQL
......
...@@ -22,4 +22,12 @@ ...@@ -22,4 +22,12 @@
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers> </providers>
</entityFramework> </entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" />
<bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> </configuration>
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<package id="EntityFramework" version="6.1.0" targetFramework="net45" /> <package id="EntityFramework" version="6.1.0" targetFramework="net45" />
<package id="FSharp.Core" version="4.0.0" targetFramework="net45" /> <package id="FSharp.Core" version="4.0.0" targetFramework="net45" />
<package id="FSPowerPack.Community" version="2.0.0.0" /> <package id="FSPowerPack.Community" version="2.0.0.0" />
<package id="Microsoft.SqlServer.Types" version="11.0.1" targetFramework="net45" />
<package id="Npgsql" version="2.0.11" /> <package id="Npgsql" version="2.0.11" />
<package id="SqlServerCompact" version="4.0.8482.1" /> <package id="SqlServerCompact" version="4.0.8482.1" />
</packages> </packages>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata schemaVersion="2"> <metadata schemaVersion="2">
<id>Dapper</id> <id>Dapper</id>
<version>1.28</version> <version>1.34</version>
<title>Dapper dot net</title> <title>Dapper dot net</title>
<authors>Sam Saffron,Marc Gravell</authors> <authors>Sam Saffron,Marc Gravell</authors>
<owners>Sam Saffron,Marc Gravell</owners> <owners>Sam Saffron,Marc Gravell</owners>
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
<frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.0-Client, .NETFramework4.0" /> <frameworkAssembly assemblyName="Microsoft.CSharp" targetFramework=".NETFramework4.0-Client, .NETFramework4.0" />
</frameworkAssemblies> </frameworkAssemblies>
<releaseNotes> <releaseNotes>
* 1.34 - Support for SqlHierarchyId (core)
* 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
* 1.29 - Make underscore name matching optional (opt-in) - this can be a breaking change for some people
* 1.28 - Much better numeric type conversion; fix for large oracle strings; map Foo_Bar to FooBar (etc); ExecuteScalar added; stability fixes * 1.28 - Much better numeric type conversion; fix for large oracle strings; map Foo_Bar to FooBar (etc); ExecuteScalar added; stability fixes
* 1.27 - Fixes for type-handler parse; ensure type-handlers get last dibs on configuring parameters * 1.27 - Fixes for type-handler parse; ensure type-handlers get last dibs on configuring parameters
* 1.26 - New type handler API for extension support * 1.26 - New type handler API for extension support
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment