Commit 9076086b authored by Nick Craver's avatar Nick Craver Committed by GitHub

Merge pull request #836 from StackExchange/netstandard2

.NET Standard 2.0, for great justice.
parents 610d8f65 9d9afeaf
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<Title>Dapper.Contrib</Title> <Title>Dapper.Contrib</Title>
<Description>The official collection of get, insert, update and delete helpers for Dapper.net. Also handles lists of entities and optional "dirty" tracking of interface-based entities.</Description> <Description>The official collection of get, insert, update and delete helpers for Dapper.net. Also handles lists of entities and optional "dirty" tracking of interface-based entities.</Description>
<Authors>Sam Saffron;Johan Danforth</Authors> <Authors>Sam Saffron;Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks> <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs --> <!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" /> <ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' "> <ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
<Reference Include="System" /> <Reference Include="System" />
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
using Dapper; using Dapper;
#if COREFX #if NETSTANDARD1_3
using DataException = System.InvalidOperationException; using DataException = System.InvalidOperationException;
#else #else
using System.Threading; using System.Threading;
...@@ -274,7 +274,7 @@ private static string GetTableName(Type type) ...@@ -274,7 +274,7 @@ private static string GetTableName(Type type)
{ {
//NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework //NOTE: This as dynamic trick should be able to handle both our own Table-attribute as well as the one in EntityFramework
var tableAttr = type var tableAttr = type
#if COREFX #if NETSTANDARD1_3
.GetTypeInfo() .GetTypeInfo()
#endif #endif
.GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic; .GetCustomAttributes(false).SingleOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic;
...@@ -516,7 +516,7 @@ private static class ProxyGenerator ...@@ -516,7 +516,7 @@ private static class ProxyGenerator
private static AssemblyBuilder GetAsmBuilder(string name) private static AssemblyBuilder GetAsmBuilder(string name)
{ {
#if COREFX #if NETSTANDARD1_3
return AssemblyBuilder.DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run); return AssemblyBuilder.DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
#else #else
return Thread.GetDomain().DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run); return Thread.GetDomain().DefineDynamicAssembly(new AssemblyName { Name = name }, AssemblyBuilderAccess.Run);
...@@ -551,7 +551,7 @@ public static T GetInterfaceProxy<T>() ...@@ -551,7 +551,7 @@ public static T GetInterfaceProxy<T>()
CreateProperty<T>(typeBuilder, property.Name, property.PropertyType, setIsDirtyMethod, isId); CreateProperty<T>(typeBuilder, property.Name, property.PropertyType, setIsDirtyMethod, isId);
} }
#if COREFX #if NETSTANDARD1_3
var generatedType = typeBuilder.CreateTypeInfo().AsType(); var generatedType = typeBuilder.CreateTypeInfo().AsType();
#else #else
var generatedType = typeBuilder.CreateType(); var generatedType = typeBuilder.CreateType();
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<Title>Dapper: Entity Framework type handlers (with a strong name)</Title> <Title>Dapper: Entity Framework type handlers (with a strong name)</Title>
<Description>Extension handlers for entity framework</Description> <Description>Extension handlers for entity framework</Description>
<Authors>Marc Gravell;Nick Craver</Authors> <Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks> <TargetFrameworks>net451</TargetFrameworks>
<AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> <PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle> <AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle>
<VersionPrefix>1.50.2</VersionPrefix> <VersionPrefix>1.50.2</VersionPrefix>
<Authors>Marc Gravell;Nick Craver</Authors> <Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45</TargetFrameworks> <TargetFrameworks>net451</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags> <PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<Description>Trivial micro-orm implemented on Dapper, provides with CRUD helpers.</Description> <Description>Trivial micro-orm implemented on Dapper, provides with CRUD helpers.</Description>
<Authors>Sam Saffron</Authors> <Authors>Sam Saffron</Authors>
<Copyright>2017 Sam Saffron</Copyright> <Copyright>2017 Sam Saffron</Copyright>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks> <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs --> <!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" /> <ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' "> <ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<Title>Dapper SqlBuilder component</Title> <Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description> <Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors> <Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net40;net45;netstandard1.3</TargetFrameworks> <TargetFrameworks>net451;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs --> <!-- TODO: Docs -->
<GenerateDocumentationFile>false</GenerateDocumentationFile> <GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" /> <ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' "> <ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" /> <PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
<Title>Dapper (Strong Named)</Title> <Title>Dapper (Strong Named)</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description> <Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors> <Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45;net451;netstandard1.3</TargetFrameworks> <TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly> <SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> <PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" /> <Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' "> <ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" /> <PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" /> <PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" /> <PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" /> <PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" /> <PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" /> <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
...@@ -30,4 +30,9 @@ ...@@ -30,4 +30,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" /> <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" /> <PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
</ItemGroup>
</Project> </Project>
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile> <GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFramework>netcoreapp1.0</TargetFramework> <TargetFrameworks>netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX;</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" /> <Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
...@@ -19,14 +16,13 @@ ...@@ -19,14 +16,13 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" /> <ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" /> <ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" /> <ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" /> <PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" /> <PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" /> <PackageReference Include="xunit" Version="$(xUnitVersion)" />
</ItemGroup> <PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' "> <DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
#if !COREFX #if !NETCOREAPP1_0 && !NETCOREAPP2_0
using System.Data.SqlServerCe;
using System.Transactions; using System.Transactions;
using System.Data.SqlServerCe;
#endif #endif
using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute; using FactAttribute = Dapper.Tests.Contrib.SkippableFactAttribute;
...@@ -420,7 +420,7 @@ public void InsertGetUpdate() ...@@ -420,7 +420,7 @@ public void InsertGetUpdate()
} }
} }
#if !COREFX #if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact(Skip = "Not parallel friendly - thinking about how to test this")] [Fact(Skip = "Not parallel friendly - thinking about how to test this")]
public void InsertWithCustomDbType() public void InsertWithCustomDbType()
{ {
...@@ -525,7 +525,7 @@ public void Transactions() ...@@ -525,7 +525,7 @@ public void Transactions()
} }
} }
#if !COREFX #if !NETCOREAPP1_0 && !NETCOREAPP2_0
[Fact] [Fact]
public void TransactionScope() public void TransactionScope()
{ {
...@@ -632,4 +632,3 @@ public void DeleteAll() ...@@ -632,4 +632,3 @@ public void DeleteAll()
} }
} }
} }
using System; using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.IO; using System.IO;
using Xunit; using Xunit;
using Xunit.Sdk; using Xunit.Sdk;
#if COREFX
using Microsoft.Data.Sqlite; #if !NETCOREAPP1_0 && !NETCOREAPP2_0
#else
using System.Data.SQLite;
using System.Data.SqlServerCe; using System.Data.SqlServerCe;
using MySql.Data.MySqlClient;
using SqliteConnection = System.Data.SQLite.SQLiteConnection;
#endif #endif
namespace Dapper.Tests.Contrib namespace Dapper.Tests.Contrib
...@@ -60,7 +58,6 @@ static SqlServerTestSuite() ...@@ -60,7 +58,6 @@ static SqlServerTestSuite()
} }
} }
#if !COREFX
public class MySqlServerTestSuite : TestSuite public class MySqlServerTestSuite : TestSuite
{ {
const string DbName = "DapperContribTests"; const string DbName = "DapperContribTests";
...@@ -115,14 +112,11 @@ static MySqlServerTestSuite() ...@@ -115,14 +112,11 @@ static MySqlServerTestSuite()
} }
} }
} }
// This doesn't work on COREFX right now due to:
// In Visual Studio: Interop loads (works from console, though)
// In general: parameter names, see https://github.com/StackExchange/dapper-dot-net/issues/375
public class SQLiteTestSuite : TestSuite public class SQLiteTestSuite : TestSuite
{ {
const string FileName = "Test.DB.sqlite"; const string FileName = "Test.DB.sqlite";
public static string ConnectionString => $"Filename={FileName};"; public static string ConnectionString => $"Filename=./{FileName};Mode=ReadWriteCreate;";
public override IDbConnection GetConnection() => new SqliteConnection(ConnectionString); public override IDbConnection GetConnection() => new SqliteConnection(ConnectionString);
static SQLiteTestSuite() static SQLiteTestSuite()
...@@ -131,7 +125,6 @@ static SQLiteTestSuite() ...@@ -131,7 +125,6 @@ static SQLiteTestSuite()
{ {
File.Delete(FileName); File.Delete(FileName);
} }
SqliteConnection.CreateFile(FileName);
using (var connection = new SqliteConnection(ConnectionString)) using (var connection = new SqliteConnection(ConnectionString))
{ {
connection.Open(); connection.Open();
...@@ -147,6 +140,7 @@ static SQLiteTestSuite() ...@@ -147,6 +140,7 @@ static SQLiteTestSuite()
} }
} }
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
public class SqlCETestSuite : TestSuite public class SqlCETestSuite : TestSuite
{ {
const string FileName = "Test.DB.sdf"; const string FileName = "Test.DB.sdf";
......
...@@ -8,7 +8,7 @@ public class BelgradeBenchmarks : BenchmarkBase ...@@ -8,7 +8,7 @@ public class BelgradeBenchmarks : BenchmarkBase
{ {
private QueryMapper _mapper; private QueryMapper _mapper;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -6,7 +6,7 @@ namespace Dapper.Tests.Performance ...@@ -6,7 +6,7 @@ namespace Dapper.Tests.Performance
{ {
public class DapperBenchmarks : BenchmarkBase public class DapperBenchmarks : BenchmarkBase
{ {
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -7,7 +7,7 @@ public class EF6Benchmarks : BenchmarkBase ...@@ -7,7 +7,7 @@ public class EF6Benchmarks : BenchmarkBase
{ {
private EntityFramework.EFContext Context; private EntityFramework.EFContext Context;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -13,7 +13,7 @@ public class EFCoreBenchmarks : BenchmarkBase ...@@ -13,7 +13,7 @@ public class EFCoreBenchmarks : BenchmarkBase
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery = private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id)); CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -9,11 +9,11 @@ public class HandCodedBenchmarks : BenchmarkBase ...@@ -9,11 +9,11 @@ public class HandCodedBenchmarks : BenchmarkBase
{ {
private SqlCommand _postCommand; private SqlCommand _postCommand;
private SqlParameter _idParam; private SqlParameter _idParam;
#if !COREFX #if !NETCOREAPP1_0
private DataTable _table; private DataTable _table;
#endif #endif
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
...@@ -24,7 +24,7 @@ public void Setup() ...@@ -24,7 +24,7 @@ public void Setup()
Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id" Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id"
}; };
_idParam = _postCommand.Parameters.Add("@Id", SqlDbType.Int); _idParam = _postCommand.Parameters.Add("@Id", SqlDbType.Int);
#if !COREFX #if !NETCOREAPP1_0
_table = new DataTable _table = new DataTable
{ {
Columns = Columns =
......
...@@ -12,7 +12,7 @@ public class Linq2SqlBenchmarks : BenchmarkBase ...@@ -12,7 +12,7 @@ public class Linq2SqlBenchmarks : BenchmarkBase
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery = private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id)); CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -8,7 +8,7 @@ public class MassiveBenchmarks : BenchmarkBase ...@@ -8,7 +8,7 @@ public class MassiveBenchmarks : BenchmarkBase
{ {
private DynamicModel _model; private DynamicModel _model;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -13,7 +13,7 @@ public class NHibernateBenchmarks : BenchmarkBase ...@@ -13,7 +13,7 @@ public class NHibernateBenchmarks : BenchmarkBase
{ {
private IStatelessSession _sql, _hql, _criteria, _linq, _get; private IStatelessSession _sql, _hql, _criteria, _linq, _get;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -8,7 +8,7 @@ public class PetaPocoBenchmarks : BenchmarkBase ...@@ -8,7 +8,7 @@ public class PetaPocoBenchmarks : BenchmarkBase
{ {
private Database _db, _dbFast; private Database _db, _dbFast;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -8,7 +8,7 @@ public class ServiceStackBenchmarks : BenchmarkBase ...@@ -8,7 +8,7 @@ public class ServiceStackBenchmarks : BenchmarkBase
{ {
private IDbConnection _db; private IDbConnection _db;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -6,7 +6,7 @@ public class SomaBenchmarks : BenchmarkBase ...@@ -6,7 +6,7 @@ public class SomaBenchmarks : BenchmarkBase
{ {
private dynamic _sdb; private dynamic _sdb;
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -18,7 +18,7 @@ public class SusanooBenchmarks : BenchmarkBase ...@@ -18,7 +18,7 @@ public class SusanooBenchmarks : BenchmarkBase
.DefineResults<dynamic>() .DefineResults<dynamic>()
.Realize(); .Realize();
[Setup] [GlobalSetup]
public void Setup() public void Setup()
{ {
BaseSetup(); BaseSetup();
......
...@@ -12,25 +12,27 @@ ...@@ -12,25 +12,27 @@
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" /> <ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" /> <ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" /> <PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.5" /> <PackageReference Include="BenchmarkDotNet" Version="0.10.9" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.5" /> <PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.9" />
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />--> <!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<PackageReference Include="EntityFramework" Version="6.1.3" /> <PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.0.1" /> <PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" /> <PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" /> <PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" /> <PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="NHibernate" Version="4.1.1.4000" /> <PackageReference Include="NHibernate" Version="4.1.1.4000" />
<PackageReference Include="Npgsql" Version="3.2.2" /> <PackageReference Include="Iesi.Collections" Version="4.0.2" />
<PackageReference Include="PetaPoco" Version="5.1.244" /> <PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.8" /> <PackageReference Include="PetaPoco" Version="5.1.259" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.12" />
<PackageReference Include="Simple.Data.SqlServer" Version="2.0.0-alpha1" /> <PackageReference Include="Simple.Data.SqlServer" Version="2.0.0-alpha1" />
<PackageReference Include="Soma" Version="1.9.0.1" /> <PackageReference Include="Soma" Version="1.9.0.1" />
<PackageReference Include="SubSonic" Version="3.0.0.4" /> <PackageReference Include="SubSonic" Version="3.0.0.4" />
<PackageReference Include="Susanoo.SqlServer" Version="1.2.4.2" /> <PackageReference Include="Susanoo.SqlServer" Version="1.2.4.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.105" /> <PackageReference Include="System.Data.SQLite" Version="1.0.105.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
......
...@@ -8,7 +8,7 @@ public class ORMColum : IColumn ...@@ -8,7 +8,7 @@ public class ORMColum : IColumn
{ {
public string Id => nameof(ORMColum); public string Id => nameof(ORMColum);
public string ColumnName { get; } = "ORM"; public string ColumnName { get; } = "ORM";
public string Legend => "The object relational mapper being tested"; public string Legend => "The object/relational mapper being tested";
public bool IsDefault(Summary summary, Benchmark benchmark) => false; public bool IsDefault(Summary summary, Benchmark benchmark) => false;
public string GetValue(Summary summary, Benchmark benchmark) => benchmark.Target.Method.DeclaringType.Name.Replace("Benchmarks", string.Empty); public string GetValue(Summary summary, Benchmark benchmark) => benchmark.Target.Method.DeclaringType.Name.Replace("Benchmarks", string.Empty);
......
...@@ -341,7 +341,7 @@ public async Task RunAsync(int iterations) ...@@ -341,7 +341,7 @@ public async Task RunAsync(int iterations)
} }
}, "Hand Coded"); }, "Hand Coded");
#if !COREFX #if !NETSTANDARD1_3
var table = new DataTable var table = new DataTable
{ {
Columns = Columns =
......
#if !COREFX #if !NETSTANDARD1_3
#pragma warning disable 1591 #pragma warning disable 1591
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
......
#if !COREFX #if !NETSTANDARD1_3
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
......
#if !COREFX #if !NETSTANDARD1_3
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
......
...@@ -218,7 +218,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault() ...@@ -218,7 +218,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault()
} }
} }
#if !COREFX #if !NETCOREAPP1_0
[Fact] [Fact]
public async Task ExecuteReaderOpenAsync() public async Task ExecuteReaderOpenAsync()
{ {
...@@ -318,8 +318,8 @@ public async Task LiteralInAsync() ...@@ -318,8 +318,8 @@ public async Task LiteralInAsync()
new { ids = new[] { 1, 3, 4 } }).ConfigureAwait(false)).Single(); new { ids = new[] { 1, 3, 4 } }).ConfigureAwait(false)).Single();
count.IsEqualTo(2); count.IsEqualTo(2);
} }
[Fact] [FactLongRunning]
public async Task RunSequentialVersusParallelAsync() public async Task RunSequentialVersusParallelAsync()
{ {
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray(); var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
...@@ -336,7 +336,7 @@ public async Task RunSequentialVersusParallelAsync() ...@@ -336,7 +336,7 @@ public async Task RunSequentialVersusParallelAsync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds); Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
} }
[Fact] [FactLongRunning]
public void RunSequentialVersusParallelSync() public void RunSequentialVersusParallelSync()
{ {
var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray(); var ids = Enumerable.Range(1, 20000).Select(id => new { id }).ToArray();
...@@ -353,28 +353,35 @@ public void RunSequentialVersusParallelSync() ...@@ -353,28 +353,35 @@ public void RunSequentialVersusParallelSync()
Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds); Console.WriteLine("Pipeline: {0}ms", watch.ElapsedMilliseconds);
} }
[Fact] [Collection(NonParallelDefinition.Name)]
public void AssertNoCacheWorksForQueryMultiple() public class AsyncQueryCacheTests : TestBase
{ {
const int a = 123, b = 456; private SqlConnection _marsConnection;
var cmdDef = new CommandDefinition(@"select @a; select @b;", new private SqlConnection MarsConnection => _marsConnection ?? (_marsConnection = GetOpenConnection(true));
{
a, b
}, commandType: CommandType.Text, flags: CommandFlags.NoCache);
int c, d; [Fact]
SqlMapper.PurgeQueryCache(); public void AssertNoCacheWorksForQueryMultiple()
int before = SqlMapper.GetCachedSQLCount();
using (var multi = MarsConnection.QueryMultiple(cmdDef))
{ {
c = multi.Read<int>().Single(); const int a = 123, b = 456;
d = multi.Read<int>().Single(); var cmdDef = new CommandDefinition(@"select @a; select @b;", new
{
a, b
}, commandType: CommandType.Text, flags: CommandFlags.NoCache);
int c, d;
SqlMapper.PurgeQueryCache();
int before = SqlMapper.GetCachedSQLCount();
using (var multi = MarsConnection.QueryMultiple(cmdDef))
{
c = multi.Read<int>().Single();
d = multi.Read<int>().Single();
}
int after = SqlMapper.GetCachedSQLCount();
before.IsEqualTo(0);
after.IsEqualTo(0);
c.IsEqualTo(123);
d.IsEqualTo(456);
} }
int after = SqlMapper.GetCachedSQLCount();
before.IsEqualTo(0);
after.IsEqualTo(0);
c.IsEqualTo(123);
d.IsEqualTo(456);
} }
private class BasicType private class BasicType
......
...@@ -104,107 +104,6 @@ public bool GetWentThroughProperConstructor() ...@@ -104,107 +104,6 @@ public bool GetWentThroughProperConstructor()
} }
} }
#if LINQ2SQL
private class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; }
public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
{
Value = val;
}
}
[Fact]
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
new Random(123456).NextBytes(orig);
var input = new System.Data.Linq.Binary(orig);
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
#endif
[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());
connection.Execute(@"CREATE TABLE #Issue461 (
Id int not null IDENTITY(1,1),
SomeValue nvarchar(50),
SomeBlargValue nvarchar(200),
)");
const string Expected = "abc123def";
var blarg = new Blarg(Expected);
connection.Execute(
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
new { value = "what up?", blarg });
// test: without constructor
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo(1);
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);
// test: via constructor
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
}
// I would usually expect this to be a struct; using a class
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; }
public string Value { get; }
public override string ToString()
{
return Value;
}
}
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{
public override void SetValue(IDbDataParameter parameter, Blarg value)
{
parameter.Value = ((object)value.Value) ?? DBNull.Value;
}
public override Blarg Parse(object value)
{
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
return new Blarg(s);
}
}
private class Issue461_ParameterlessTypeConstructor
{
public int Id { get; set; }
public string SomeValue { get; set; }
public Blarg SomeBlargValue { get; set; }
}
private class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{
Id = id;
SomeValue = someValue;
SomeBlargValue = someBlargValue;
}
public int Id { get; }
public string SomeValue { get; }
public Blarg SomeBlargValue { get; }
}
public static class AbstractInheritance public static class AbstractInheritance
{ {
public abstract class Order public abstract class Order
......
...@@ -6,14 +6,13 @@ ...@@ -6,14 +6,13 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile> <GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks> <TargetFrameworks>net452;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' "> <PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45;MYSQL;ENTITY_FRAMEWORK;LINQ2SQL;FIREBIRD;SQL_CE;POSTGRESQL;OLEDB;SQLITE</DefineConstants> <DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;SQL_CE;OLEDB</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Test.DB.sdf" /> <None Remove="Test.DB.sdf" />
...@@ -21,23 +20,22 @@ ...@@ -21,23 +20,22 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" /> <ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" /> <ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" /> <PackageReference Include="MySql.Data" Version="8.0.8-dmr" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" /> <PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" /> <PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" /> <PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' "> <ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" /> <ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" /> <PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" /> <PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="System.Data.SQLite" Version="1.0.104" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
...@@ -47,9 +45,12 @@ ...@@ -47,9 +45,12 @@
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' "> <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
<PackageReference Include="System.Ben" Version="1.0.0" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" /> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace Dapper.Tests namespace Dapper.Tests
{ {
public partial class DataReaderTests : TestBase public class DataReaderTests : TestBase
{ {
[Fact] [Fact]
public void GetSameReaderForSameShape() public void GetSameReaderForSameShape()
...@@ -137,18 +137,13 @@ private abstract class Discriminated_BaseType ...@@ -137,18 +137,13 @@ private abstract class Discriminated_BaseType
private class Discriminated_Foo : Discriminated_BaseType private class Discriminated_Foo : Discriminated_BaseType
{ {
public string Name { get; set; } public string Name { get; set; }
public override int Type { public override int Type => 1;
get { return 1; }
}
} }
private class Discriminated_Bar : Discriminated_BaseType private class Discriminated_Bar : Discriminated_BaseType
{ {
public float Value { get; set; } public float Value { get; set; }
public override int Type public override int Type => 2;
{
get { return 2; }
}
} }
private abstract class DiscriminatedWithMultiMapping_BaseType : Discriminated_BaseType private abstract class DiscriminatedWithMultiMapping_BaseType : Discriminated_BaseType
...@@ -160,20 +155,14 @@ private class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_ ...@@ -160,20 +155,14 @@ private class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_
{ {
public override HazNameId HazNameIdObject { get; set; } public override HazNameId HazNameIdObject { get; set; }
public string Name { get; set; } public string Name { get; set; }
public override int Type public override int Type => 1;
{
get { return 1; }
}
} }
private class DiscriminatedWithMultiMapping_Bar : DiscriminatedWithMultiMapping_BaseType private class DiscriminatedWithMultiMapping_Bar : DiscriminatedWithMultiMapping_BaseType
{ {
public override HazNameId HazNameIdObject { get; set; } public override HazNameId HazNameIdObject { get; set; }
public float Value { get; set; } public float Value { get; set; }
public override int Type public override int Type => 2;
{
get { return 2; }
}
} }
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit; using Xunit;
namespace Dapper.Tests namespace Dapper.Tests
......
...@@ -4,20 +4,6 @@ ...@@ -4,20 +4,6 @@
namespace Dapper.Tests namespace Dapper.Tests
{ {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactUnlessCoreCLRAttribute : FactAttribute
{
public FactUnlessCoreCLRAttribute(string url)
{
#if COREFX
Skip = $"CoreFX: {url}";
#endif
this.Url = url;
}
public string Url { get; }
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class FactLongRunningAttribute : FactAttribute public sealed class FactLongRunningAttribute : FactAttribute
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
using System.Linq; using System.Linq;
using Xunit; using Xunit;
#if COREFX #if NETCOREAPP1_0
using System.Collections; using System.Collections;
using System.Dynamic; using System.Dynamic;
using System.Data.SqlTypes; using System.Data.SqlTypes;
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
#endif #endif
#if COREFX #if NETCOREAPP1_0
namespace System namespace System
{ {
public enum GenericUriParserOptions public enum GenericUriParserOptions
...@@ -507,7 +507,7 @@ public void TestInheritance() ...@@ -507,7 +507,7 @@ public void TestInheritance()
list.First().Base2.IsEqualTo("Four"); list.First().Base2.IsEqualTo("Four");
} }
#if !COREFX #if !NETCOREAPP1_0
[Fact] [Fact]
public void ExecuteReader() public void ExecuteReader()
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
namespace Dapper.Tests namespace Dapper.Tests
{ {
[Collection(NonParallelDefinition.Name)]
public class NullTests : TestBase public class NullTests : TestBase
{ {
[Fact] [Fact]
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
using Xunit; using Xunit;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Diagnostics;
#if ENTITY_FRAMEWORK #if ENTITY_FRAMEWORK
using System.Data.Entity.Spatial; using System.Data.Entity.Spatial;
...@@ -37,6 +38,24 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id ...@@ -37,6 +38,24 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Id
} }
} }
private static List<Microsoft.SqlServer.Server.SqlDataRecord> CreateSqlDataRecordList(IEnumerable<int> numbers)
{
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>();
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
return number_list;
}
private class IntDynamicParam : SqlMapper.IDynamicParameters private class IntDynamicParam : SqlMapper.IDynamicParameters
{ {
private readonly IEnumerable<int> numbers; private readonly IEnumerable<int> numbers;
...@@ -50,19 +69,8 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity) ...@@ -50,19 +69,8 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var sqlCommand = (SqlCommand)command; var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>(); var number_list = CreateSqlDataRecordList(numbers);
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
// Add the table parameter. // Add the table parameter.
var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured); var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);
p.Direction = ParameterDirection.Input; p.Direction = ParameterDirection.Input;
...@@ -84,19 +92,8 @@ public void AddParameter(IDbCommand command, string name) ...@@ -84,19 +92,8 @@ public void AddParameter(IDbCommand command, string name)
var sqlCommand = (SqlCommand)command; var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>(); var number_list = CreateSqlDataRecordList(numbers);
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
// Add the table parameter. // Add the table parameter.
var p = sqlCommand.Parameters.Add(name, SqlDbType.Structured); var p = sqlCommand.Parameters.Add(name, SqlDbType.Structured);
p.Direction = ParameterDirection.Input; p.Direction = ParameterDirection.Input;
...@@ -217,7 +214,6 @@ public void TestMassiveStrings() ...@@ -217,7 +214,6 @@ public void TestMassiveStrings()
.IsEqualTo(str); .IsEqualTo(str);
} }
#if !COREFX
[Fact] [Fact]
public void TestTVPWithAnonymousObject() public void TestTVPWithAnonymousObject()
{ {
...@@ -288,19 +284,8 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity) ...@@ -288,19 +284,8 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var sqlCommand = (SqlCommand)command; var sqlCommand = (SqlCommand)command;
sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandType = CommandType.StoredProcedure;
var number_list = new List<Microsoft.SqlServer.Server.SqlDataRecord>(); var number_list = CreateSqlDataRecordList(numbers);
// Create an SqlMetaData object that describes our table type.
Microsoft.SqlServer.Server.SqlMetaData[] tvp_definition = { new Microsoft.SqlServer.Server.SqlMetaData("n", SqlDbType.Int) };
foreach (int n in numbers)
{
// Create a new record, using the metadata array above.
var rec = new Microsoft.SqlServer.Server.SqlDataRecord(tvp_definition);
rec.SetInt32(0, n); // Set the value.
number_list.Add(rec); // Add it to the list.
}
// Add the table parameter. // Add the table parameter.
var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured); var p = sqlCommand.Parameters.Add("ints", SqlDbType.Structured);
p.Direction = ParameterDirection.Input; p.Direction = ParameterDirection.Input;
...@@ -343,6 +328,83 @@ public void TestTVPWithAdditionalParams() ...@@ -343,6 +328,83 @@ public void TestTVPWithAdditionalParams()
} }
} }
[Fact]
public void TestSqlDataRecordListParametersWithAsTableValuedParameter()
{
try
{
connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)");
connection.Execute("CREATE PROC get_ints @integers int_list_type READONLY AS select * from @integers");
var records = CreateSqlDataRecordList(new int[] { 1, 2, 3 });
var nums = connection.Query<int>("get_ints", new { integers = records.AsTableValuedParameter() }, commandType: CommandType.StoredProcedure).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
nums = connection.Query<int>("select * from @integers", new { integers = records.AsTableValuedParameter("int_list_type") }).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
try
{
connection.Query<int>("select * from @integers", new { integers = records.AsTableValuedParameter() }).First();
throw new InvalidOperationException();
}
catch (Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
}
finally
{
try
{
connection.Execute("DROP PROC get_ints");
}
finally
{
connection.Execute("DROP TYPE int_list_type");
}
}
}
[Fact]
public void TestSqlDataRecordListParametersWithTypeHandlers()
{
try
{
connection.Execute("CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)");
connection.Execute("CREATE PROC get_ints @integers int_list_type READONLY AS select * from @integers");
// Variable type has to be IEnumerable<SqlDataRecord> for TypeHandler to kick in.
IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord> records = CreateSqlDataRecordList(new int[] { 1, 2, 3 });
var nums = connection.Query<int>("get_ints", new { integers = records }, commandType: CommandType.StoredProcedure).ToList();
nums.IsSequenceEqualTo(new int[] { 1, 2, 3 });
try
{
connection.Query<int>("select * from @integers", new { integers = records }).First();
throw new InvalidOperationException();
}
catch (Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
}
finally
{
try
{
connection.Execute("DROP PROC get_ints");
}
finally
{
connection.Execute("DROP TYPE int_list_type");
}
}
}
#if !NETCOREAPP1_0
[Fact] [Fact]
public void DataTableParameters() public void DataTableParameters()
{ {
...@@ -491,7 +553,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName) ...@@ -491,7 +553,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName)
public void AddParameters(IDbCommand command, SqlMapper.Identity identity) public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
{ {
Console.WriteLine("> AddParameters"); Debug.WriteLine("> AddParameters");
var lazy = (SqlCommand)command; var lazy = (SqlCommand)command;
lazy.Parameters.AddWithValue("Id", 7); lazy.Parameters.AddWithValue("Id", 7);
var table = new DataTable var table = new DataTable
...@@ -500,7 +562,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity) ...@@ -500,7 +562,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
Rows = { { 4 }, { 9 } } Rows = { { 4 }, { 9 } }
}; };
lazy.Parameters.AddWithValue("Rules", table); lazy.Parameters.AddWithValue("Rules", table);
Console.WriteLine("< AddParameters"); Debug.WriteLine("< AddParameters");
} }
} }
......
...@@ -103,7 +103,7 @@ public void SO24605346_ProcsAndStrings() ...@@ -103,7 +103,7 @@ public void SO24605346_ProcsAndStrings()
private class PracticeRebateOrders private class PracticeRebateOrders
{ {
public string fTaxInvoiceNumber; public string fTaxInvoiceNumber;
#if !COREFX #if !NETCOREAPP1_0
[System.Xml.Serialization.XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] [System.Xml.Serialization.XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
#endif #endif
public string TaxInvoiceNumber public string TaxInvoiceNumber
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace Dapper.Tests.Providers namespace Dapper.Tests.Providers
{ {
[Collection("TypeHandlerTests")]
public class EntityFrameworkTests : TestBase public class EntityFrameworkTests : TestBase
{ {
public EntityFrameworkTests() public EntityFrameworkTests()
......
#if FIREBIRD using FirebirdSql.Data.FirebirdClient;
using FirebirdSql.Data.FirebirdClient;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
...@@ -45,5 +44,4 @@ public void Issue178_Firebird() ...@@ -45,5 +44,4 @@ public void Issue178_Firebird()
} }
} }
} }
} }
#endif \ No newline at end of file
\ No newline at end of file
...@@ -38,6 +38,27 @@ private class WithBinary ...@@ -38,6 +38,27 @@ private class WithBinary
{ {
public System.Data.Linq.Binary Value { get; set; } public System.Data.Linq.Binary Value { get; set; }
} }
private class NoDefaultConstructorWithBinary
{
public System.Data.Linq.Binary Value { get; set; }
public int Ynt { get; set; }
public NoDefaultConstructorWithBinary(System.Data.Linq.Binary val)
{
Value = val;
}
}
[Fact]
public void TestNoDefaultConstructorBinary()
{
byte[] orig = new byte[20];
new Random(123456).NextBytes(orig);
var input = new System.Data.Linq.Binary(orig);
var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
output.ToArray().IsSequenceEqualTo(orig);
}
} }
} }
#endif #endif
\ No newline at end of file
#if MYSQL using System;
using System;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
...@@ -186,4 +185,3 @@ static FactMySqlAttribute() ...@@ -186,4 +185,3 @@ static FactMySqlAttribute()
} }
} }
} }
#endif
#if POSTGRESQL using System;
using System;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using Xunit; using Xunit;
...@@ -80,5 +79,4 @@ static FactPostgresqlAttribute() ...@@ -80,5 +79,4 @@ static FactPostgresqlAttribute()
} }
} }
} }
} }
#endif \ No newline at end of file
\ No newline at end of file
#if SQLITE using Microsoft.Data.Sqlite;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Data.SQLite;
using System.Data;
using Xunit; using Xunit;
namespace Dapper.Tests namespace Dapper.Tests
{ {
public class SqliteTests : TestBase public class SqliteTests : TestBase
{ {
protected static SQLiteConnection GetSQLiteConnection(bool open = true) protected static SqliteConnection GetSQLiteConnection(bool open = true)
{ {
var connection = new SQLiteConnection("Data Source=:memory:"); var connection = new SqliteConnection("Data Source=:memory:");
if (open) connection.Open(); if (open) connection.Open();
return connection; return connection;
} }
...@@ -26,41 +24,45 @@ public void DapperEnumValue_Sqlite() ...@@ -26,41 +24,45 @@ public void DapperEnumValue_Sqlite()
} }
} }
[FactSqlite] [Collection(NonParallelDefinition.Name)]
public void Issue466_SqliteHatesOptimizations() public class SqliteTypeHandlerTests : TestBase
{ {
using (var connection = GetSQLiteConnection()) [FactSqlite]
public void Issue466_SqliteHatesOptimizations()
{ {
SqlMapper.ResetTypeHandlers(); using (var connection = GetSQLiteConnection())
var row = connection.Query<HazNameId>("select 42 as Id").First(); {
row.Id.IsEqualTo(42); SqlMapper.ResetTypeHandlers();
row = connection.Query<HazNameId>("select 42 as Id").First(); var row = connection.Query<HazNameId>("select 42 as Id").First();
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
row = connection.Query<HazNameId>("select 42 as Id").First();
row.Id.IsEqualTo(42);
SqlMapper.ResetTypeHandlers(); SqlMapper.ResetTypeHandlers();
row = connection.QueryFirst<HazNameId>("select 42 as Id"); row = connection.QueryFirst<HazNameId>("select 42 as Id");
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
row = connection.QueryFirst<HazNameId>("select 42 as Id"); row = connection.QueryFirst<HazNameId>("select 42 as Id");
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
}
} }
}
[FactSqlite] [FactSqlite]
public async Task Issue466_SqliteHatesOptimizations_Async() public async Task Issue466_SqliteHatesOptimizations_Async()
{
using (var connection = GetSQLiteConnection())
{ {
SqlMapper.ResetTypeHandlers(); using (var connection = GetSQLiteConnection())
var row = (await connection.QueryAsync<HazNameId>("select 42 as Id").ConfigureAwait(false)).First(); {
row.Id.IsEqualTo(42); SqlMapper.ResetTypeHandlers();
row = (await connection.QueryAsync<HazNameId>("select 42 as Id").ConfigureAwait(false)).First(); var row = (await connection.QueryAsync<HazNameId>("select 42 as Id").ConfigureAwait(false)).First();
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
row = (await connection.QueryAsync<HazNameId>("select 42 as Id").ConfigureAwait(false)).First();
row.Id.IsEqualTo(42);
SqlMapper.ResetTypeHandlers(); SqlMapper.ResetTypeHandlers();
row = await connection.QueryFirstAsync<HazNameId>("select 42 as Id").ConfigureAwait(false); row = await connection.QueryFirstAsync<HazNameId>("select 42 as Id").ConfigureAwait(false);
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
row = await connection.QueryFirstAsync<HazNameId>("select 42 as Id").ConfigureAwait(false); row = await connection.QueryFirstAsync<HazNameId>("select 42 as Id").ConfigureAwait(false);
row.Id.IsEqualTo(42); row.Id.IsEqualTo(42);
}
} }
} }
...@@ -82,11 +84,7 @@ private void Isse467_SqliteParameterNaming(bool prefix) ...@@ -82,11 +84,7 @@ private void Isse467_SqliteParameterNaming(bool prefix)
{ {
var cmd = connection.CreateCommand(); var cmd = connection.CreateCommand();
cmd.CommandText = "select @foo"; cmd.CommandText = "select @foo";
#if NET45
const DbType type = DbType.Int32;
#else
const SqliteType type = SqliteType.Integer; const SqliteType type = SqliteType.Integer;
#endif
cmd.Parameters.Add(prefix ? "@foo" : "foo", type).Value = 42; cmd.Parameters.Add(prefix ? "@foo" : "foo", type).Value = 42;
var i = Convert.ToInt32(cmd.ExecuteScalar()); var i = Convert.ToInt32(cmd.ExecuteScalar());
i.IsEqualTo(42); i.IsEqualTo(42);
...@@ -118,5 +116,4 @@ static FactSqliteAttribute() ...@@ -118,5 +116,4 @@ static FactSqliteAttribute()
} }
} }
} }
} }
#endif \ No newline at end of file
\ No newline at end of file
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Globalization; using System.Globalization;
#if !COREFX using Xunit;
#if !NETCOREAPP1_0
using System.Threading; using System.Threading;
#endif #endif
...@@ -45,7 +46,7 @@ public SqlConnection GetClosedConnection() ...@@ -45,7 +46,7 @@ public SqlConnection GetClosedConnection()
protected static CultureInfo ActiveCulture protected static CultureInfo ActiveCulture
{ {
#if COREFX #if NETCOREAPP1_0
get { return CultureInfo.CurrentCulture; } get { return CultureInfo.CurrentCulture; }
set { CultureInfo.CurrentCulture = value; } set { CultureInfo.CurrentCulture = value; }
#else #else
...@@ -58,8 +59,8 @@ static TestBase() ...@@ -58,8 +59,8 @@ static TestBase()
{ {
Console.WriteLine("Dapper: " + typeof(SqlMapper).AssemblyQualifiedName); Console.WriteLine("Dapper: " + typeof(SqlMapper).AssemblyQualifiedName);
Console.WriteLine("Using Connectionstring: {0}", ConnectionString); Console.WriteLine("Using Connectionstring: {0}", ConnectionString);
#if COREFX #if NETCOREAPP1_0
Console.WriteLine("CoreCLR"); Console.WriteLine("CoreCLR (netcoreapp1.0)");
#else #else
Console.WriteLine(".NET: " + Environment.Version); Console.WriteLine(".NET: " + Environment.Version);
Console.Write("Loading native assemblies for SQL types..."); Console.Write("Loading native assemblies for SQL types...");
...@@ -81,4 +82,10 @@ public void Dispose() ...@@ -81,4 +82,10 @@ public void Dispose()
_connection?.Dispose(); _connection?.Dispose();
} }
} }
[CollectionDefinition(Name, DisableParallelization = true)]
public class NonParallelDefinition : TestBase
{
public const string Name = "NonParallel";
}
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Dapper.Tests namespace Dapper.Tests
{ {
[Collection(NonParallelDefinition.Name)]
public class TypeHandlerTests : TestBase public class TypeHandlerTests : TestBase
{ {
[Fact] [Fact]
...@@ -48,6 +49,51 @@ public void TestChangingDefaultStringTypeMappingToAnsiStringFirstOrDefault() ...@@ -48,6 +49,51 @@ public void TestChangingDefaultStringTypeMappingToAnsiStringFirstOrDefault()
SqlMapper.AddTypeMap(typeof(string), DbType.String); // Restore Default to Unicode String SqlMapper.AddTypeMap(typeof(string), DbType.String); // Restore Default to Unicode String
} }
[Fact]
public void TestCustomTypeMap()
{
// default mapping
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName));
SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("BVal");
item.B.IsEqualTo("AVal");
// reset to default
SqlMapper.SetTypeMap(typeof(TypeWithMapping), null);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
}
private static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if NETCOREAPP1_0
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return (string)data?.ConstructorArguments.Single().Value;
#else
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
return attrib?.Description;
#endif
}
public class TypeWithMapping
{
[Description("B")]
public string A { get; set; }
[Description("A")]
public string B { get; set; }
}
[Fact] [Fact]
public void Issue136_ValueTypeHandlers() public void Issue136_ValueTypeHandlers()
{ {
...@@ -230,52 +276,52 @@ private void TestBigIntForEverythingWorks_ByDataType<T>(string dbType) ...@@ -230,52 +276,52 @@ private void TestBigIntForEverythingWorks_ByDataType<T>(string dbType)
row.N_P_Long.Value.IsEqualTo(LotsOfNumerics.E_Long.B); row.N_P_Long.Value.IsEqualTo(LotsOfNumerics.E_Long.B);
row.N_P_ULong.Value.IsEqualTo(LotsOfNumerics.E_ULong.B); row.N_P_ULong.Value.IsEqualTo(LotsOfNumerics.E_ULong.B);
TestBigIntForEverythingWorks<bool>(true, dbType); TestBigIntForEverythingWorksGeneric<bool>(true, dbType);
TestBigIntForEverythingWorks<sbyte>((sbyte)1, dbType); TestBigIntForEverythingWorksGeneric<sbyte>((sbyte)1, dbType);
TestBigIntForEverythingWorks<byte>((byte)1, dbType); TestBigIntForEverythingWorksGeneric<byte>((byte)1, dbType);
TestBigIntForEverythingWorks<int>((int)1, dbType); TestBigIntForEverythingWorksGeneric<int>((int)1, dbType);
TestBigIntForEverythingWorks<uint>((uint)1, dbType); TestBigIntForEverythingWorksGeneric<uint>((uint)1, dbType);
TestBigIntForEverythingWorks<short>((short)1, dbType); TestBigIntForEverythingWorksGeneric<short>((short)1, dbType);
TestBigIntForEverythingWorks<ushort>((ushort)1, dbType); TestBigIntForEverythingWorksGeneric<ushort>((ushort)1, dbType);
TestBigIntForEverythingWorks<long>((long)1, dbType); TestBigIntForEverythingWorksGeneric<long>((long)1, dbType);
TestBigIntForEverythingWorks<ulong>((ulong)1, dbType); TestBigIntForEverythingWorksGeneric<ulong>((ulong)1, dbType);
TestBigIntForEverythingWorks<float>((float)1, dbType); TestBigIntForEverythingWorksGeneric<float>((float)1, dbType);
TestBigIntForEverythingWorks<double>((double)1, dbType); TestBigIntForEverythingWorksGeneric<double>((double)1, dbType);
TestBigIntForEverythingWorks<decimal>((decimal)1, dbType); TestBigIntForEverythingWorksGeneric<decimal>((decimal)1, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Byte.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_SByte.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Int.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_UInt.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Short.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_UShort.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_Long.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorks(LotsOfNumerics.E_ULong.B, dbType); TestBigIntForEverythingWorksGeneric(LotsOfNumerics.E_ULong.B, dbType);
TestBigIntForEverythingWorks<bool?>(true, dbType); TestBigIntForEverythingWorksGeneric<bool?>(true, dbType);
TestBigIntForEverythingWorks<sbyte?>((sbyte)1, dbType); TestBigIntForEverythingWorksGeneric<sbyte?>((sbyte)1, dbType);
TestBigIntForEverythingWorks<byte?>((byte)1, dbType); TestBigIntForEverythingWorksGeneric<byte?>((byte)1, dbType);
TestBigIntForEverythingWorks<int?>((int)1, dbType); TestBigIntForEverythingWorksGeneric<int?>((int)1, dbType);
TestBigIntForEverythingWorks<uint?>((uint)1, dbType); TestBigIntForEverythingWorksGeneric<uint?>((uint)1, dbType);
TestBigIntForEverythingWorks<short?>((short)1, dbType); TestBigIntForEverythingWorksGeneric<short?>((short)1, dbType);
TestBigIntForEverythingWorks<ushort?>((ushort)1, dbType); TestBigIntForEverythingWorksGeneric<ushort?>((ushort)1, dbType);
TestBigIntForEverythingWorks<long?>((long)1, dbType); TestBigIntForEverythingWorksGeneric<long?>((long)1, dbType);
TestBigIntForEverythingWorks<ulong?>((ulong)1, dbType); TestBigIntForEverythingWorksGeneric<ulong?>((ulong)1, dbType);
TestBigIntForEverythingWorks<float?>((float)1, dbType); TestBigIntForEverythingWorksGeneric<float?>((float)1, dbType);
TestBigIntForEverythingWorks<double?>((double)1, dbType); TestBigIntForEverythingWorksGeneric<double?>((double)1, dbType);
TestBigIntForEverythingWorks<decimal?>((decimal)1, dbType); TestBigIntForEverythingWorksGeneric<decimal?>((decimal)1, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Byte?>(LotsOfNumerics.E_Byte.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Byte?>(LotsOfNumerics.E_Byte.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_SByte?>(LotsOfNumerics.E_SByte.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_SByte?>(LotsOfNumerics.E_SByte.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Int?>(LotsOfNumerics.E_Int.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Int?>(LotsOfNumerics.E_Int.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_UInt?>(LotsOfNumerics.E_UInt.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_UInt?>(LotsOfNumerics.E_UInt.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Short?>(LotsOfNumerics.E_Short.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Short?>(LotsOfNumerics.E_Short.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_UShort?>(LotsOfNumerics.E_UShort.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_UShort?>(LotsOfNumerics.E_UShort.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_Long?>(LotsOfNumerics.E_Long.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_Long?>(LotsOfNumerics.E_Long.B, dbType);
TestBigIntForEverythingWorks<LotsOfNumerics.E_ULong?>(LotsOfNumerics.E_ULong.B, dbType); TestBigIntForEverythingWorksGeneric<LotsOfNumerics.E_ULong?>(LotsOfNumerics.E_ULong.B, dbType);
} }
private void TestBigIntForEverythingWorks<T>(T expected, string dbType) private void TestBigIntForEverythingWorksGeneric<T>(T expected, string dbType)
{ {
var query = connection.Query<T>("select cast(1 as " + dbType + ")").Single(); var query = connection.Query<T>("select cast(1 as " + dbType + ")").Single();
query.IsEqualTo(expected); query.IsEqualTo(expected);
...@@ -462,7 +508,7 @@ public void Test_RemoveTypeMap() ...@@ -462,7 +508,7 @@ public void Test_RemoveTypeMap()
try try
{ {
connection.Execute(@"INSERT INTO #Test_RemoveTypeMap VALUES (@Now)", new { DateTime.Now }); connection.Execute("INSERT INTO #Test_RemoveTypeMap VALUES (@Now)", new { DateTime.Now });
connection.Query<DateTime>("SELECT * FROM #Test_RemoveTypeMap"); connection.Query<DateTime>("SELECT * FROM #Test_RemoveTypeMap");
dateTimeHandler.ParseWasCalled.IsTrue(); dateTimeHandler.ParseWasCalled.IsTrue();
...@@ -518,51 +564,6 @@ private class ResultsChangeType ...@@ -518,51 +564,6 @@ private class ResultsChangeType
public int Z { get; set; } public int Z { get; set; }
} }
[Fact]
public void TestCustomTypeMap()
{
// default mapping
var item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
// custom mapping
var map = new CustomPropertyTypeMap(typeof(TypeWithMapping),
(type, columnName) => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName));
SqlMapper.SetTypeMap(typeof(TypeWithMapping), map);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("BVal");
item.B.IsEqualTo("AVal");
// reset to default
SqlMapper.SetTypeMap(typeof(TypeWithMapping), null);
item = connection.Query<TypeWithMapping>("Select 'AVal' as A, 'BVal' as B").Single();
item.A.IsEqualTo("AVal");
item.B.IsEqualTo("BVal");
}
private static string GetDescriptionFromAttribute(MemberInfo member)
{
if (member == null) return null;
#if COREFX
var data = member.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DescriptionAttribute));
return (string)data?.ConstructorArguments.Single().Value;
#else
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false);
return attrib?.Description;
#endif
}
public class TypeWithMapping
{
[Description("B")]
public string A { get; set; }
[Description("A")]
public string B { get; set; }
}
public class WrongTypes public class WrongTypes
{ {
public int A { get; set; } public int A { get; set; }
...@@ -634,7 +635,7 @@ public void Issue149_TypeMismatch_SequentialAccess() ...@@ -634,7 +635,7 @@ public void Issue149_TypeMismatch_SequentialAccess()
Guid guid = Guid.Parse("cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e"); Guid guid = Guid.Parse("cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e");
try try
{ {
var result = connection.Query<Issue149_Person>(@"select @guid as Id", new { guid }).First(); var result = connection.Query<Issue149_Person>("select @guid as Id", new { guid }).First();
error = null; error = null;
} }
catch (Exception ex) catch (Exception ex)
...@@ -658,5 +659,84 @@ public void SO29343103_UtcDates() ...@@ -658,5 +659,84 @@ public void SO29343103_UtcDates()
var delta = returned - date; var delta = returned - date;
Assert.IsTrue(delta.TotalMilliseconds >= -10 && delta.TotalMilliseconds <= 10); Assert.IsTrue(delta.TotalMilliseconds >= -10 && delta.TotalMilliseconds <= 10);
} }
[Fact]
public void Issue461_TypeHandlerWorksInConstructor()
{
SqlMapper.AddTypeHandler(new Issue461_BlargHandler());
connection.Execute(@"CREATE TABLE #Issue461 (
Id int not null IDENTITY(1,1),
SomeValue nvarchar(50),
SomeBlargValue nvarchar(200),
)");
const string Expected = "abc123def";
var blarg = new Blarg(Expected);
connection.Execute(
"INSERT INTO #Issue461 (SomeValue, SomeBlargValue) VALUES (@value, @blarg)",
new { value = "what up?", blarg });
// test: without constructor
var parameterlessWorks = connection.QuerySingle<Issue461_ParameterlessTypeConstructor>("SELECT * FROM #Issue461");
parameterlessWorks.Id.IsEqualTo(1);
parameterlessWorks.SomeValue.IsEqualTo("what up?");
parameterlessWorks.SomeBlargValue.Value.IsEqualTo(Expected);
// test: via constructor
var parameterDoesNot = connection.QuerySingle<Issue461_ParameterisedTypeConstructor>("SELECT * FROM #Issue461");
parameterDoesNot.Id.IsEqualTo(1);
parameterDoesNot.SomeValue.IsEqualTo("what up?");
parameterDoesNot.SomeBlargValue.Value.IsEqualTo(Expected);
}
// I would usually expect this to be a struct; using a class
// so that we can't pass unexpectedly due to forcing an unsafe cast - want
// to see an InvalidCastException if it is wrong
private class Blarg
{
public Blarg(string value) { Value = value; }
public string Value { get; }
public override string ToString()
{
return Value;
}
}
private class Issue461_BlargHandler : SqlMapper.TypeHandler<Blarg>
{
public override void SetValue(IDbDataParameter parameter, Blarg value)
{
parameter.Value = ((object)value.Value) ?? DBNull.Value;
}
public override Blarg Parse(object value)
{
string s = (value == null || value is DBNull) ? null : Convert.ToString(value);
return new Blarg(s);
}
}
private class Issue461_ParameterlessTypeConstructor
{
public int Id { get; set; }
public string SomeValue { get; set; }
public Blarg SomeBlargValue { get; set; }
}
private class Issue461_ParameterisedTypeConstructor
{
public Issue461_ParameterisedTypeConstructor(int id, string someValue, Blarg someBlargValue)
{
Id = id;
SomeValue = someValue;
SomeBlargValue = someBlargValue;
}
public int Id { get; }
public string SomeValue { get; }
public Blarg SomeBlargValue { get; }
}
} }
} }
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26403.7 VisualStudioVersion = 15.0.26730.8
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.ps1 = build.ps1 build.ps1 = build.ps1
build.sh = build.sh build.sh = build.sh
Directory.build.props = Directory.build.props
License.txt = License.txt License.txt = License.txt
nuget.config = nuget.config
Readme.md = Readme.md Readme.md = Readme.md
semver.txt = semver.txt
EndProjectSection EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Dapper\Dapper.csproj", "{FAC24C3F-68F9-4247-A4B9-21D487E99275}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Dapper\Dapper.csproj", "{FAC24C3F-68F9-4247-A4B9-21D487E99275}"
...@@ -101,4 +103,7 @@ Global ...@@ -101,4 +103,7 @@ Global
{39D3EEB6-9C05-4F4A-8C01-7B209742A7EB} = {4E956F6B-6BD8-46F5-BC85-49292FF8F9AB} {39D3EEB6-9C05-4F4A-8C01-7B209742A7EB} = {4E956F6B-6BD8-46F5-BC85-49292FF8F9AB}
{F017075A-2969-4A8E-8971-26F154EB420F} = {568BD46C-1C65-4D44-870C-12CD72563262} {F017075A-2969-4A8E-8971-26F154EB420F} = {568BD46C-1C65-4D44-870C-12CD72563262}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {928A4226-96F3-409A-8A83-9E7444488710}
EndGlobalSection
EndGlobal EndGlobal
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
<Title>Dapper</Title> <Title>Dapper</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description> <Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors> <Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net40;net45;net451;netstandard1.3</TargetFrameworks> <TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451' "> <ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' "> <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" /> <PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" /> <PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" /> <PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" /> <PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" /> <PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" /> <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
...@@ -25,4 +25,9 @@ ...@@ -25,4 +25,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" /> <PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" /> <PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
</ItemGroup>
</Project> </Project>
using System; using System;
using System.Data; using System.Data;
#if !COREFX #if !NETSTANDARD1_3
namespace Dapper namespace Dapper
{ {
internal sealed class DataTableHandler : SqlMapper.ITypeHandler internal sealed class DataTableHandler : SqlMapper.ITypeHandler
......
...@@ -26,7 +26,7 @@ public DefaultTypeMap(Type type) ...@@ -26,7 +26,7 @@ public DefaultTypeMap(Type type)
Properties = GetSettableProps(type); Properties = GetSettableProps(type);
_type = type; _type = type;
} }
#if COREFX #if NETSTANDARD1_3
private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y) private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
{ {
if (ReferenceEquals(x, y)) return true; if (ReferenceEquals(x, y)) return true;
...@@ -40,7 +40,7 @@ private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y) ...@@ -40,7 +40,7 @@ private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type) internal static MethodInfo GetPropertySetter(PropertyInfo propertyInfo, Type type)
{ {
if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true); if (propertyInfo.DeclaringType == type) return propertyInfo.GetSetMethod(true);
#if COREFX #if NETSTANDARD1_3
return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) return propertyInfo.DeclaringType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Single(x => x.Name == propertyInfo.Name .Single(x => x.Name == propertyInfo.Name
&& x.PropertyType == propertyInfo.PropertyType && x.PropertyType == propertyInfo.PropertyType
...@@ -118,7 +118,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types) ...@@ -118,7 +118,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public ConstructorInfo FindExplicitConstructor() public ConstructorInfo FindExplicitConstructor()
{ {
var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
#if COREFX #if NETSTANDARD1_3
var withAttr = constructors.Where(c => c.CustomAttributes.Any(x => x.AttributeType == typeof(ExplicitConstructorAttribute))).ToList(); var withAttr = constructors.Where(c => c.CustomAttributes.Any(x => x.AttributeType == typeof(ExplicitConstructorAttribute))).ToList();
#else #else
var withAttr = constructors.Where(c => c.GetCustomAttributes(typeof(ExplicitConstructorAttribute), true).Length > 0).ToList(); var withAttr = constructors.Where(c => c.GetCustomAttributes(typeof(ExplicitConstructorAttribute), true).Length > 0).ToList();
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
#if COREFX #if NETSTANDARD1_3
using ApplicationException = System.InvalidOperationException; using ApplicationException = System.InvalidOperationException;
#endif #endif
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
#if !COREFX
namespace Dapper namespace Dapper
{ {
internal sealed class SqlDataRecordHandler : SqlMapper.ITypeHandler internal sealed class SqlDataRecordHandler : SqlMapper.ITypeHandler
...@@ -18,4 +17,3 @@ public void SetValue(IDbDataParameter parameter, object value) ...@@ -18,4 +17,3 @@ public void SetValue(IDbDataParameter parameter, object value)
} }
} }
} }
#endif
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Reflection;
#if !COREFX
namespace Dapper namespace Dapper
{ {
/// <summary> /// <summary>
...@@ -23,18 +22,6 @@ public SqlDataRecordListTVPParameter(IEnumerable<Microsoft.SqlServer.Server.SqlD ...@@ -23,18 +22,6 @@ public SqlDataRecordListTVPParameter(IEnumerable<Microsoft.SqlServer.Server.SqlD
this.typeName = typeName; this.typeName = typeName;
} }
private static readonly Action<System.Data.SqlClient.SqlParameter, string> setTypeName;
static SqlDataRecordListTVPParameter()
{
var prop = typeof(System.Data.SqlClient.SqlParameter).GetProperty(nameof(System.Data.SqlClient.SqlParameter.TypeName), BindingFlags.Instance | BindingFlags.Public);
if (prop != null && prop.PropertyType == typeof(string) && prop.CanWrite)
{
setTypeName = (Action<System.Data.SqlClient.SqlParameter, string>)
Delegate.CreateDelegate(typeof(Action<System.Data.SqlClient.SqlParameter, string>), prop.GetSetMethod());
}
}
void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name) void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{ {
var param = command.CreateParameter(); var param = command.CreateParameter();
...@@ -54,4 +41,3 @@ internal static void Set(IDbDataParameter parameter, IEnumerable<Microsoft.SqlSe ...@@ -54,4 +41,3 @@ internal static void Set(IDbDataParameter parameter, IEnumerable<Microsoft.SqlSe
} }
} }
} }
#endif
\ No newline at end of file
...@@ -11,7 +11,7 @@ public static partial class SqlMapper ...@@ -11,7 +11,7 @@ public static partial class SqlMapper
/// </summary> /// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam> /// <typeparam name="T">The type to have a cache for.</typeparam>
[Obsolete(ObsoleteInternalUsageOnly, false)] [Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
#if COREFX #if NETSTANDARD1_3
using DataException = System.InvalidOperationException; using DataException = System.InvalidOperationException;
#endif #endif
...@@ -217,26 +217,24 @@ static SqlMapper() ...@@ -217,26 +217,24 @@ static SqlMapper()
private static void ResetTypeHandlers(bool clone) private static void ResetTypeHandlers(bool clone)
{ {
typeHandlers = new Dictionary<Type, ITypeHandler>(); typeHandlers = new Dictionary<Type, ITypeHandler>();
#if !COREFX #if !NETSTANDARD1_3
AddTypeHandlerImpl(typeof(DataTable), new DataTableHandler(), clone); AddTypeHandlerImpl(typeof(DataTable), new DataTableHandler(), clone);
#endif
try try
{ {
AddSqlDataRecordsTypeHandler(clone); AddSqlDataRecordsTypeHandler(clone);
} }
catch { /* https://github.com/StackExchange/dapper-dot-net/issues/424 */ } catch { /* https://github.com/StackExchange/dapper-dot-net/issues/424 */ }
#endif
AddTypeHandlerImpl(typeof(XmlDocument), new XmlDocumentHandler(), clone); AddTypeHandlerImpl(typeof(XmlDocument), new XmlDocumentHandler(), clone);
AddTypeHandlerImpl(typeof(XDocument), new XDocumentHandler(), clone); AddTypeHandlerImpl(typeof(XDocument), new XDocumentHandler(), clone);
AddTypeHandlerImpl(typeof(XElement), new XElementHandler(), clone); AddTypeHandlerImpl(typeof(XElement), new XElementHandler(), clone);
} }
#if !COREFX
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
private static void AddSqlDataRecordsTypeHandler(bool clone) private static void AddSqlDataRecordsTypeHandler(bool clone)
{ {
AddTypeHandlerImpl(typeof(IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord>), new SqlDataRecordHandler(), clone); AddTypeHandlerImpl(typeof(IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord>), new SqlDataRecordHandler(), clone);
} }
#endif
/// <summary> /// <summary>
/// Configure the specified type to be mapped to a given db-type. /// Configure the specified type to be mapped to a given db-type.
...@@ -348,7 +346,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon ...@@ -348,7 +346,7 @@ public static void AddTypeHandlerImpl(Type type, ITypeHandler handler, bool clon
/// </summary> /// </summary>
/// <param name="value">The object to get a corresponding database type for.</param> /// <param name="value">The object to get a corresponding database type for.</param>
[Obsolete(ObsoleteInternalUsageOnly, false)] [Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -367,7 +365,7 @@ public static DbType GetDbType(object value) ...@@ -367,7 +365,7 @@ public static DbType GetDbType(object value)
/// <param name="demand">Whether to demand a value (throw if missing).</param> /// <param name="demand">Whether to demand a value (throw if missing).</param>
/// <param name="handler">The handler for <paramref name="type"/>.</param> /// <param name="handler">The handler for <paramref name="type"/>.</param>
[Obsolete(ObsoleteInternalUsageOnly, false)] [Obsolete(ObsoleteInternalUsageOnly, false)]
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -397,7 +395,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType ...@@ -397,7 +395,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
return DynamicParameters.EnumerableMultiParameter; return DynamicParameters.EnumerableMultiParameter;
} }
#if !COREFX #if !NETSTANDARD1_3 && !NETSTANDARD2_0
switch (type.FullName) switch (type.FullName)
{ {
case "Microsoft.SqlServer.Types.SqlGeography": case "Microsoft.SqlServer.Types.SqlGeography":
...@@ -1864,7 +1862,7 @@ private static Exception MultiMapException(IDataRecord reader) ...@@ -1864,7 +1862,7 @@ private static Exception MultiMapException(IDataRecord reader)
/// Internal use only. /// Internal use only.
/// </summary> /// </summary>
/// <param name="value">The object to convert to a character.</param> /// <param name="value">The object to convert to a character.</param>
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -1881,7 +1879,7 @@ public static char ReadChar(object value) ...@@ -1881,7 +1879,7 @@ public static char ReadChar(object value)
/// Internal use only. /// Internal use only.
/// </summary> /// </summary>
/// <param name="value">The object to convert to a character.</param> /// <param name="value">The object to convert to a character.</param>
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -1900,7 +1898,7 @@ public static char ReadChar(object value) ...@@ -1900,7 +1898,7 @@ public static char ReadChar(object value)
/// <param name="parameters">The parameter collection to search in.</param> /// <param name="parameters">The parameter collection to search in.</param>
/// <param name="command">The command for this fetch.</param> /// <param name="command">The command for this fetch.</param>
/// <param name="name">The name of the parameter to get.</param> /// <param name="name">The name of the parameter to get.</param>
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -1958,7 +1956,7 @@ internal static int GetListPaddingExtraCount(int count) ...@@ -1958,7 +1956,7 @@ internal static int GetListPaddingExtraCount(int count)
/// <param name="command">The command to pack parameters for.</param> /// <param name="command">The command to pack parameters for.</param>
/// <param name="namePrefix">The name prefix for these parameters.</param> /// <param name="namePrefix">The name prefix for these parameters.</param>
/// <param name="value">The parameter value can be an <see cref="IEnumerable{T}"/></param> /// <param name="value">The parameter value can be an <see cref="IEnumerable{T}"/></param>
#if !COREFX #if !NETSTANDARD1_3
[Browsable(false)] [Browsable(false)]
#endif #endif
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
...@@ -2257,7 +2255,7 @@ public static string Format(object value) ...@@ -2257,7 +2255,7 @@ public static string Format(object value)
{ {
switch (TypeExtensions.GetTypeCode(value.GetType())) switch (TypeExtensions.GetTypeCode(value.GetType()))
{ {
#if !COREFX #if !NETSTANDARD1_3
case TypeCode.DBNull: case TypeCode.DBNull:
return "null"; return "null";
#endif #endif
...@@ -3080,7 +3078,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo ...@@ -3080,7 +3078,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
int index = startBound; int index = startBound;
ConstructorInfo specializedConstructor = null; ConstructorInfo specializedConstructor = null;
#if !COREFX #if !NETSTANDARD1_3
bool supportInitialize = false; bool supportInitialize = false;
#endif #endif
Dictionary<Type, LocalBuilder> structLocals = null; Dictionary<Type, LocalBuilder> structLocals = null;
...@@ -3115,7 +3113,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo ...@@ -3115,7 +3113,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Newobj, explicitConstr); il.Emit(OpCodes.Newobj, explicitConstr);
il.Emit(OpCodes.Stloc_1); il.Emit(OpCodes.Stloc_1);
#if !COREFX #if !NETSTANDARD1_3
supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type); supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);
if (supportInitialize) if (supportInitialize)
{ {
...@@ -3137,7 +3135,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo ...@@ -3137,7 +3135,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
{ {
il.Emit(OpCodes.Newobj, ctor); il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Stloc_1); il.Emit(OpCodes.Stloc_1);
#if !COREFX #if !NETSTANDARD1_3
supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type); supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);
if (supportInitialize) if (supportInitialize)
{ {
...@@ -3354,7 +3352,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo ...@@ -3354,7 +3352,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il.Emit(OpCodes.Newobj, specializedConstructor); il.Emit(OpCodes.Newobj, specializedConstructor);
} }
il.Emit(OpCodes.Stloc_1); // stack is empty il.Emit(OpCodes.Stloc_1); // stack is empty
#if !COREFX #if !NETSTANDARD1_3
if (supportInitialize) if (supportInitialize)
{ {
il.Emit(OpCodes.Ldloc_1); il.Emit(OpCodes.Ldloc_1);
...@@ -3626,7 +3624,7 @@ public static IEqualityComparer<string> ConnectionStringComparer ...@@ -3626,7 +3624,7 @@ public static IEqualityComparer<string> ConnectionStringComparer
private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal; private static IEqualityComparer<string> connectionStringComparer = StringComparer.Ordinal;
#if !COREFX #if !NETSTANDARD1_3
/// <summary> /// <summary>
/// Key used to indicate the type name associated with a DataTable. /// Key used to indicate the type name associated with a DataTable.
/// </summary> /// </summary>
...@@ -3662,15 +3660,15 @@ public static void SetTypeName(this DataTable table, string typeName) ...@@ -3662,15 +3660,15 @@ public static void SetTypeName(this DataTable table, string typeName)
/// <param name="table">The <see cref="DataTable"/> that has a type name associated with it.</param> /// <param name="table">The <see cref="DataTable"/> that has a type name associated with it.</param>
public static string GetTypeName(this DataTable table) => public static string GetTypeName(this DataTable table) =>
table?.ExtendedProperties[DataTableTypeNameKey] as string; table?.ExtendedProperties[DataTableTypeNameKey] as string;
#endif
/// <summary> /// <summary>
/// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a <see cref="TableValuedParameter"/>. /// Used to pass a IEnumerable&lt;SqlDataRecord&gt; as a TableValuedParameter.
/// </summary> /// </summary>
/// <param name="list">Thhe list of records to convert to TVPs.</param> /// <param name="list">The list of records to convert to TVPs.</param>
/// <param name="typeName">The sql parameter type name.</param> /// <param name="typeName">The sql parameter type name.</param>
public static ICustomQueryParameter AsTableValuedParameter(this IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord> list, string typeName = null) => public static ICustomQueryParameter AsTableValuedParameter(this IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord> list, string typeName = null) =>
new SqlDataRecordListTVPParameter(list, typeName); new SqlDataRecordListTVPParameter(list, typeName);
#endif
// one per thread // one per thread
[ThreadStatic] [ThreadStatic]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Data; using System.Data;
using System.Reflection; using System.Reflection;
#if !COREFX #if !NETSTANDARD1_3
namespace Dapper namespace Dapper
{ {
/// <summary> /// <summary>
......
...@@ -7,41 +7,41 @@ namespace Dapper ...@@ -7,41 +7,41 @@ namespace Dapper
internal static class TypeExtensions internal static class TypeExtensions
{ {
public static string Name(this Type type) => public static string Name(this Type type) =>
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().Name; type.GetTypeInfo().Name;
#else #else
type.Name; type.Name;
#endif #endif
public static bool IsValueType(this Type type) => public static bool IsValueType(this Type type) =>
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsValueType; type.GetTypeInfo().IsValueType;
#else #else
type.IsValueType; type.IsValueType;
#endif #endif
public static bool IsEnum(this Type type) => public static bool IsEnum(this Type type) =>
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsEnum; type.GetTypeInfo().IsEnum;
#else #else
type.IsEnum; type.IsEnum;
#endif #endif
public static bool IsGenericType(this Type type) => public static bool IsGenericType(this Type type) =>
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsGenericType; type.GetTypeInfo().IsGenericType;
#else #else
type.IsGenericType; type.IsGenericType;
#endif #endif
public static bool IsInterface(this Type type) => public static bool IsInterface(this Type type) =>
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
type.GetTypeInfo().IsInterface; type.GetTypeInfo().IsInterface;
#else #else
type.IsInterface; type.IsInterface;
#endif #endif
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
public static IEnumerable<Attribute> GetCustomAttributes(this Type type, bool inherit) public static IEnumerable<Attribute> GetCustomAttributes(this Type type, bool inherit)
{ {
return type.GetTypeInfo().GetCustomAttributes(inherit); return type.GetTypeInfo().GetCustomAttributes(inherit);
...@@ -85,7 +85,7 @@ public static TypeCode GetTypeCode(Type type) ...@@ -85,7 +85,7 @@ public static TypeCode GetTypeCode(Type type)
public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Type[] types) public static MethodInfo GetPublicInstanceMethod(this Type type, string name, Type[] types)
{ {
#if COREFX #if NETSTANDARD1_3 || NETCOREAPP1_0
var method = type.GetMethod(name, types); var method = type.GetMethod(name, types);
return (method?.IsPublic == true && !method.IsStatic) ? method : null; return (method?.IsPublic == true && !method.IsStatic) ? method : null;
#else #else
......
...@@ -5,7 +5,7 @@ namespace Dapper ...@@ -5,7 +5,7 @@ namespace Dapper
{ {
public static partial class SqlMapper public static partial class SqlMapper
{ {
#if !COREFX #if !NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary> /// <summary>
/// A type handler for data-types that are supported by the underlying provider, but which need /// A type handler for data-types that are supported by the underlying provider, but which need
/// a well-known UdtTypeName to be specified /// a well-known UdtTypeName to be specified
......
...@@ -19,28 +19,20 @@ ...@@ -19,28 +19,20 @@
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage> <DefaultLanguage>en-US</DefaultLanguage>
<IncludeSymbols>false</IncludeSymbols> <IncludeSymbols>false</IncludeSymbols>
<xUnitVersion>2.3.0-beta5-build3750</xUnitVersion>
</PropertyGroup> </PropertyGroup>
<!-- Workarounds for https://github.com/NuGet/Home/issues/4853 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'">
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'"> <ItemGroup Condition="'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'">
<Reference Include="System.Core" Pack="false" /> <Reference Include="System.Core" Pack="false" />
</ItemGroup> </ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'"> <PropertyGroup Condition=" '$(TargetFramework)' != 'net40'">
<DefineConstants>$(DefineConstants);ASYNC</DefineConstants> <DefineConstants>$(DefineConstants);ASYNC</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);ASYNC;COREFX</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="2.0.2" PrivateAssets="All" /> <PackageReference Include="SourceLink.Create.GitHub" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="4.3.0-preview1-4045" PrivateAssets="All" /> <DotNetCliToolReference Include="dotnet-sourcelink" Version="2.1.2" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.0.2" /> <DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.1.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.0.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -52,4 +52,4 @@ deploy: ...@@ -52,4 +52,4 @@ deploy:
branch: master branch: master
api_key: api_key:
secure: P/UHxq2DEs0GI1SoDXDesHjRVsSVgdywz5vmsnhFQQY5aJgO3kP+QfhwfhXz19Rw secure: P/UHxq2DEs0GI1SoDXDesHjRVsSVgdywz5vmsnhFQQY5aJgO3kP+QfhwfhXz19Rw
symbol_server: https://www.myget.org/F/stackoverflow/symbols/api/v2/package symbol_server: https://www.myget.org/F/stackoverflow/symbols/api/v2/package
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="xUnit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
\ No newline at end of file
1.50.3-alpha1 1.50.4-alpha1
\ No newline at end of file \ No newline at end of file
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