Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
9076086b
Commit
9076086b
authored
Aug 21, 2017
by
Nick Craver
Committed by
GitHub
Aug 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #836 from StackExchange/netstandard2
.NET Standard 2.0, for great justice.
parents
610d8f65
9d9afeaf
Changes
62
Hide whitespace changes
Inline
Side-by-side
Showing
62 changed files
with
547 additions
and
517 deletions
+547
-517
Dapper.Contrib.csproj
Dapper.Contrib/Dapper.Contrib.csproj
+2
-2
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+4
-4
Dapper.EntityFramework.StrongName.csproj
...ework.StrongName/Dapper.EntityFramework.StrongName.csproj
+1
-1
Dapper.EntityFramework.csproj
Dapper.EntityFramework/Dapper.EntityFramework.csproj
+1
-1
Dapper.Rainbow.csproj
Dapper.Rainbow/Dapper.Rainbow.csproj
+3
-3
Dapper.SqlBuilder.csproj
Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
+3
-3
Dapper.StrongName.csproj
Dapper.StrongName/Dapper.StrongName.csproj
+8
-3
Dapper.Tests.Contrib.csproj
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
+8
-12
TestSuite.cs
Dapper.Tests.Contrib/TestSuite.cs
+4
-5
TestSuites.cs
Dapper.Tests.Contrib/TestSuites.cs
+8
-14
Benchmarks.Belgrade.cs
Dapper.Tests.Performance/Benchmarks.Belgrade.cs
+1
-1
Benchmarks.Dapper.cs
Dapper.Tests.Performance/Benchmarks.Dapper.cs
+1
-1
Benchmarks.EntityFramework.cs
Dapper.Tests.Performance/Benchmarks.EntityFramework.cs
+1
-1
Benchmarks.EntityFrameworkCore.cs
Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs
+1
-1
Benchmarks.HandCoded.cs
Dapper.Tests.Performance/Benchmarks.HandCoded.cs
+3
-3
Benchmarks.Linq2Sql.cs
Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs
+1
-1
Benchmarks.Massive.cs
Dapper.Tests.Performance/Benchmarks.Massive.cs
+1
-1
Benchmarks.NHibernate.cs
Dapper.Tests.Performance/Benchmarks.NHibernate.cs
+1
-1
Benchmarks.PetaPoco.cs
Dapper.Tests.Performance/Benchmarks.PetaPoco.cs
+1
-1
Benchmarks.ServiceStack.cs
Dapper.Tests.Performance/Benchmarks.ServiceStack.cs
+1
-1
Benchmarks.Soma.cs
Dapper.Tests.Performance/Benchmarks.Soma.cs
+1
-1
Benchmarks.Susanoo.cs
Dapper.Tests.Performance/Benchmarks.Susanoo.cs
+1
-1
Dapper.Tests.Performance.csproj
Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
+9
-7
ORMColum.cs
Dapper.Tests.Performance/Helpers/ORMColum.cs
+1
-1
LegacyTests.cs
Dapper.Tests.Performance/LegacyTests.cs
+1
-1
DataClasses.designer.cs
Dapper.Tests.Performance/Linq2Sql/DataClasses.designer.cs
+1
-1
Massive.cs
Dapper.Tests.Performance/Massive/Massive.cs
+1
-1
PetaPoco.cs
Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
+1
-1
AsyncTests.cs
Dapper.Tests/AsyncTests.cs
+29
-22
ConstructorTests.cs
Dapper.Tests/ConstructorTests.cs
+0
-101
Dapper.Tests.csproj
Dapper.Tests/Dapper.Tests.csproj
+22
-21
DataReaderTests.cs
Dapper.Tests/DataReaderTests.cs
+5
-16
DecimalTests.cs
Dapper.Tests/DecimalTests.cs
+0
-3
Attributes.cs
Dapper.Tests/Helpers/Attributes.cs
+0
-14
MiscTests.cs
Dapper.Tests/MiscTests.cs
+3
-3
NullTests.cs
Dapper.Tests/NullTests.cs
+1
-0
ParameterTests.cs
Dapper.Tests/ParameterTests.cs
+104
-42
ProcedureTests.cs
Dapper.Tests/ProcedureTests.cs
+1
-1
EntityFrameworkTests.cs
Dapper.Tests/Providers/EntityFrameworkTests.cs
+1
-0
FirebirdTests.cs
Dapper.Tests/Providers/FirebirdTests.cs
+2
-4
Linq2SqlTests.cs
Dapper.Tests/Providers/Linq2SqlTests.cs
+21
-0
MySQLTests.cs
Dapper.Tests/Providers/MySQLTests.cs
+1
-3
PostgresqlTests.cs
Dapper.Tests/Providers/PostgresqlTests.cs
+2
-4
SqliteTests.cs
Dapper.Tests/Providers/SqliteTests.cs
+36
-39
TestBase.cs
Dapper.Tests/TestBase.cs
+11
-4
TypeHandlerTests.cs
Dapper.Tests/TypeHandlerTests.cs
+173
-93
Dapper.sln
Dapper.sln
+7
-2
Dapper.csproj
Dapper/Dapper.csproj
+8
-3
DataTableHandler.cs
Dapper/DataTableHandler.cs
+1
-1
DefaultTypeMap.cs
Dapper/DefaultTypeMap.cs
+3
-3
DynamicParameters.cs
Dapper/DynamicParameters.cs
+1
-1
SqlDataRecordHandler.cs
Dapper/SqlDataRecordHandler.cs
+0
-2
SqlDataRecordListTVPParameter.cs
Dapper/SqlDataRecordListTVPParameter.cs
+1
-15
SqlMapper.TypeHandlerCache.cs
Dapper/SqlMapper.TypeHandlerCache.cs
+1
-1
SqlMapper.cs
Dapper/SqlMapper.cs
+19
-21
TableValuedParameter.cs
Dapper/TableValuedParameter.cs
+1
-1
TypeExtensions.cs
Dapper/TypeExtensions.cs
+7
-7
UdtTypeHandler.cs
Dapper/UdtTypeHandler.cs
+1
-1
Directory.build.props
Directory.build.props
+5
-13
appveyor.yml
appveyor.yml
+1
-1
nuget.config
nuget.config
+8
-0
semver.txt
semver.txt
+1
-1
No files found.
Dapper.Contrib/Dapper.Contrib.csproj
View file @
9076086b
...
...
@@ -5,7 +5,7 @@
<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>
<Authors>Sam Saffron;Johan Danforth</Authors>
<TargetFrameworks>net4
0;net45
;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net4
51
;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
...
...
@@ -15,7 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net451'
">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
9076086b
...
...
@@ -9,7 +9,7 @@
using
Dapper
;
#if
COREFX
#if
NETSTANDARD1_3
using
DataException
=
System
.
InvalidOperationException
;
#else
using
System.Threading
;
...
...
@@ -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
var
tableAttr
=
type
#if
COREFX
#if
NETSTANDARD1_3
.
GetTypeInfo
()
#endif
.
GetCustomAttributes
(
false
).
SingleOrDefault
(
attr
=>
attr
.
GetType
().
Name
==
"TableAttribute"
)
as
dynamic
;
...
...
@@ -516,7 +516,7 @@ private static class ProxyGenerator
private
static
AssemblyBuilder
GetAsmBuilder
(
string
name
)
{
#if
COREFX
#if
NETSTANDARD1_3
return
AssemblyBuilder
.
DefineDynamicAssembly
(
new
AssemblyName
{
Name
=
name
},
AssemblyBuilderAccess
.
Run
);
#else
return
Thread
.
GetDomain
().
DefineDynamicAssembly
(
new
AssemblyName
{
Name
=
name
},
AssemblyBuilderAccess
.
Run
);
...
...
@@ -551,7 +551,7 @@ public static T GetInterfaceProxy<T>()
CreateProperty
<
T
>(
typeBuilder
,
property
.
Name
,
property
.
PropertyType
,
setIsDirtyMethod
,
isId
);
}
#if
COREFX
#if
NETSTANDARD1_3
var
generatedType
=
typeBuilder
.
CreateTypeInfo
().
AsType
();
#else
var
generatedType
=
typeBuilder
.
CreateType
();
...
...
Dapper.EntityFramework.StrongName/Dapper.EntityFramework.StrongName.csproj
View file @
9076086b
...
...
@@ -4,7 +4,7 @@
<Title>Dapper: Entity Framework type handlers (with a strong name)</Title>
<Description>Extension handlers for entity framework</Description>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net4
0;net45
</TargetFrameworks>
<TargetFrameworks>net4
51
</TargetFrameworks>
<AssemblyOriginatorKeyFile>../Dapper.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
...
...
Dapper.EntityFramework/Dapper.EntityFramework.csproj
View file @
9076086b
...
...
@@ -5,7 +5,7 @@
<AssemblyTitle>Dapper entity framework type handlers</AssemblyTitle>
<VersionPrefix>1.50.2</VersionPrefix>
<Authors>Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net4
0;net45
</TargetFrameworks>
<TargetFrameworks>net4
51
</TargetFrameworks>
<PackageTags>orm;sql;micro-orm</PackageTags>
</PropertyGroup>
<ItemGroup>
...
...
Dapper.Rainbow/Dapper.Rainbow.csproj
View file @
9076086b
...
...
@@ -6,7 +6,7 @@
<Description>Trivial micro-orm implemented on Dapper, provides with CRUD helpers.</Description>
<Authors>Sam Saffron</Authors>
<Copyright>2017 Sam Saffron</Copyright>
<TargetFrameworks>net4
0;net45
;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net4
51
;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
...
...
@@ -16,14 +16,14 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net451'
">
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'netstandard1.3'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'netstandard1.3'
">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.SqlBuilder/Dapper.SqlBuilder.csproj
View file @
9076086b
...
...
@@ -5,7 +5,7 @@
<Title>Dapper SqlBuilder component</Title>
<Description>The Dapper SqlBuilder component, for building SQL queries dynamically.</Description>
<Authors>Sam Saffron, Johan Danforth</Authors>
<TargetFrameworks>net4
0;net45
;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net4
51
;netstandard1.3</TargetFrameworks>
<!-- TODO: Docs -->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
...
...
@@ -13,13 +13,13 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net451'
">
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'netstandard1.3'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'netstandard1.3'
">
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
</Project>
\ No newline at end of file
Dapper.StrongName/Dapper.StrongName.csproj
View file @
9076086b
...
...
@@ -5,14 +5,14 @@
<Title>Dapper (Strong Named)</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net4
0;net45;net451;netstandard1.3
</TargetFrameworks>
<TargetFrameworks>net4
51;netstandard1.3;netstandard2.0
</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper\**\*.cs" Exclude="..\Dapper\obj\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net451'
">
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
...
...
@@ -22,7 +22,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" 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.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
...
...
@@ -30,4 +30,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</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>
Dapper.Tests.Contrib/Dapper.Tests.Contrib.csproj
View file @
9076086b
...
...
@@ -6,10 +6,7 @@
<DebugType>portable</DebugType>
<OutputType>Exe</OutputType>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX;</DefineConstants>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Dapper.Tests\Helpers\Assert.cs;..\Dapper.Tests\Helpers\XunitSkippable.cs;..\Dapper\TypeExtensions.cs" />
...
...
@@ -19,14 +16,13 @@
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.SqlBuilder\Dapper.SqlBuilder.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
...
...
Dapper.Tests.Contrib/TestSuite.cs
View file @
9076086b
...
...
@@ -5,9 +5,9 @@
using
Dapper.Contrib.Extensions
;
#if !COREFX
using
System.Data.SqlServerCe
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Transactions
;
using
System.Data.SqlServerCe
;
#endif
using
FactAttribute
=
Dapper
.
Tests
.
Contrib
.
SkippableFactAttribute
;
...
...
@@ -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"
)]
public
void
InsertWithCustomDbType
()
{
...
...
@@ -525,7 +525,7 @@ public void Transactions()
}
}
#if !
COREFX
#if !
NETCOREAPP1_0 && !NETCOREAPP2_0
[
Fact
]
public
void
TransactionScope
()
{
...
...
@@ -632,4 +632,3 @@ public void DeleteAll()
}
}
}
Dapper.Tests.Contrib/TestSuites.cs
View file @
9076086b
using
System
;
using
Microsoft.Data.Sqlite
;
using
MySql.Data.MySqlClient
;
using
System
;
using
System.Data
;
using
System.Data.SqlClient
;
using
System.IO
;
using
Xunit
;
using
Xunit.Sdk
;
#if COREFX
using
Microsoft.Data.Sqlite
;
#else
using
System.Data.SQLite
;
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
using
System.Data.SqlServerCe
;
using
MySql.Data.MySqlClient
;
using
SqliteConnection
=
System
.
Data
.
SQLite
.
SQLiteConnection
;
#endif
namespace
Dapper.Tests.Contrib
...
...
@@ -60,7 +58,6 @@ static SqlServerTestSuite()
}
}
#if !COREFX
public
class
MySqlServerTestSuite
:
TestSuite
{
const
string
DbName
=
"DapperContribTests"
;
...
...
@@ -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
{
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
);
static
SQLiteTestSuite
()
...
...
@@ -131,7 +125,6 @@ static SQLiteTestSuite()
{
File
.
Delete
(
FileName
);
}
SqliteConnection
.
CreateFile
(
FileName
);
using
(
var
connection
=
new
SqliteConnection
(
ConnectionString
))
{
connection
.
Open
();
...
...
@@ -147,6 +140,7 @@ static SQLiteTestSuite()
}
}
#if !NETCOREAPP1_0 && !NETCOREAPP2_0
public
class
SqlCETestSuite
:
TestSuite
{
const
string
FileName
=
"Test.DB.sdf"
;
...
...
Dapper.Tests.Performance/Benchmarks.Belgrade.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@ public class BelgradeBenchmarks : BenchmarkBase
{
private
QueryMapper
_mapper
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.Dapper.cs
View file @
9076086b
...
...
@@ -6,7 +6,7 @@ namespace Dapper.Tests.Performance
{
public
class
DapperBenchmarks
:
BenchmarkBase
{
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.EntityFramework.cs
View file @
9076086b
...
...
@@ -7,7 +7,7 @@ public class EF6Benchmarks : BenchmarkBase
{
private
EntityFramework
.
EFContext
Context
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs
View file @
9076086b
...
...
@@ -13,7 +13,7 @@ public class EFCoreBenchmarks : BenchmarkBase
private
static
readonly
Func
<
DataClassesDataContext
,
int
,
Linq2Sql
.
Post
>
compiledQuery
=
CompiledQuery
.
Compile
((
DataClassesDataContext
ctx
,
int
id
)
=>
ctx
.
Posts
.
First
(
p
=>
p
.
Id
==
id
));
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.HandCoded.cs
View file @
9076086b
...
...
@@ -9,11 +9,11 @@ public class HandCodedBenchmarks : BenchmarkBase
{
private
SqlCommand
_postCommand
;
private
SqlParameter
_idParam
;
#if !
COREFX
#if !
NETCOREAPP1_0
private
DataTable
_table
;
#endif
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
@@ -24,7 +24,7 @@ public void Setup()
Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9 from Posts where Id = @Id"
};
_idParam
=
_postCommand
.
Parameters
.
Add
(
"@Id"
,
SqlDbType
.
Int
);
#if !
COREFX
#if !
NETCOREAPP1_0
_table
=
new
DataTable
{
Columns
=
...
...
Dapper.Tests.Performance/Benchmarks.Linq2Sql.cs
View file @
9076086b
...
...
@@ -12,7 +12,7 @@ public class Linq2SqlBenchmarks : BenchmarkBase
private
static
readonly
Func
<
DataClassesDataContext
,
int
,
Linq2Sql
.
Post
>
compiledQuery
=
CompiledQuery
.
Compile
((
DataClassesDataContext
ctx
,
int
id
)
=>
ctx
.
Posts
.
First
(
p
=>
p
.
Id
==
id
));
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.Massive.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@ public class MassiveBenchmarks : BenchmarkBase
{
private
DynamicModel
_model
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.NHibernate.cs
View file @
9076086b
...
...
@@ -13,7 +13,7 @@ public class NHibernateBenchmarks : BenchmarkBase
{
private
IStatelessSession
_sql
,
_hql
,
_criteria
,
_linq
,
_get
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.PetaPoco.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@ public class PetaPocoBenchmarks : BenchmarkBase
{
private
Database
_db
,
_dbFast
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.ServiceStack.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@ public class ServiceStackBenchmarks : BenchmarkBase
{
private
IDbConnection
_db
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.Soma.cs
View file @
9076086b
...
...
@@ -6,7 +6,7 @@ public class SomaBenchmarks : BenchmarkBase
{
private
dynamic
_sdb
;
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Benchmarks.Susanoo.cs
View file @
9076086b
...
...
@@ -18,7 +18,7 @@ public class SusanooBenchmarks : BenchmarkBase
.
DefineResults
<
dynamic
>()
.
Realize
();
[
Setup
]
[
Global
Setup
]
public
void
Setup
()
{
BaseSetup
();
...
...
Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
View file @
9076086b
...
...
@@ -12,25 +12,27 @@
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="Belgrade.Sql.Client" Version="0.7.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.
5
" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.
5
" />
<PackageReference Include="BenchmarkDotNet" Version="0.10.
9
" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.10.
9
" />
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<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.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
<PackageReference Include="NHibernate" Version="4.1.1.4000" />
<PackageReference Include="Npgsql" Version="3.2.2" />
<PackageReference Include="PetaPoco" Version="5.1.244" />
<PackageReference Include="ServiceStack.OrmLite.SqlServer.Signed" Version="4.5.8" />
<PackageReference Include="Iesi.Collections" Version="4.0.2" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<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="Soma" Version="1.9.0.1" />
<PackageReference Include="SubSonic" Version="3.0.0.4" />
<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.Data" />
<Reference Include="System.Data.Linq" />
...
...
Dapper.Tests.Performance/Helpers/ORMColum.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@ public class ORMColum : IColumn
{
public
string
Id
=>
nameof
(
ORMColum
);
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
string
GetValue
(
Summary
summary
,
Benchmark
benchmark
)
=>
benchmark
.
Target
.
Method
.
DeclaringType
.
Name
.
Replace
(
"Benchmarks"
,
string
.
Empty
);
...
...
Dapper.Tests.Performance/LegacyTests.cs
View file @
9076086b
...
...
@@ -341,7 +341,7 @@ public async Task RunAsync(int iterations)
}
},
"Hand Coded"
);
#if !
COREFX
#if !
NETSTANDARD1_3
var
table
=
new
DataTable
{
Columns
=
...
...
Dapper.Tests.Performance/Linq2Sql/DataClasses.designer.cs
View file @
9076086b
#
if
!
COREFX
#
if
!
NETSTANDARD1_3
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
...
...
Dapper.Tests.Performance/Massive/Massive.cs
View file @
9076086b
#
if
!
COREFX
#
if
!
NETSTANDARD1_3
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Specialized
;
...
...
Dapper.Tests.Performance/PetaPoco/PetaPoco.cs
View file @
9076086b
#
if
!
COREFX
#
if
!
NETSTANDARD1_3
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
Dapper.Tests/AsyncTests.cs
View file @
9076086b
...
...
@@ -218,7 +218,7 @@ public async Task TestMultiClosedConnAsyncViaFirstOrDefault()
}
}
#if !
COREFX
#if !
NETCOREAPP1_0
[
Fact
]
public
async
Task
ExecuteReaderOpenAsync
()
{
...
...
@@ -318,8 +318,8 @@ public async Task LiteralInAsync()
new
{
ids
=
new
[]
{
1
,
3
,
4
}
}).
ConfigureAwait
(
false
)).
Single
();
count
.
IsEqualTo
(
2
);
}
[
Fact
]
[
Fact
LongRunning
]
public
async
Task
RunSequentialVersusParallelAsync
()
{
var
ids
=
Enumerable
.
Range
(
1
,
20000
).
Select
(
id
=>
new
{
id
}).
ToArray
();
...
...
@@ -336,7 +336,7 @@ public async Task RunSequentialVersusParallelAsync()
Console
.
WriteLine
(
"Pipeline: {0}ms"
,
watch
.
ElapsedMilliseconds
);
}
[
Fact
]
[
Fact
LongRunning
]
public
void
RunSequentialVersusParallelSync
()
{
var
ids
=
Enumerable
.
Range
(
1
,
20000
).
Select
(
id
=>
new
{
id
}).
ToArray
();
...
...
@@ -353,28 +353,35 @@ public void RunSequentialVersusParallelSync()
Console
.
WriteLine
(
"Pipeline: {0}ms"
,
watch
.
ElapsedMilliseconds
);
}
[
Fact
]
public
void
AssertNoCacheWorksForQueryMultiple
()
[
Collection
(
NonParallelDefinition
.
Name
)
]
public
class
AsyncQueryCacheTests
:
TestBase
{
const
int
a
=
123
,
b
=
456
;
var
cmdDef
=
new
CommandDefinition
(
@"select @a; select @b;"
,
new
{
a
,
b
},
commandType
:
CommandType
.
Text
,
flags
:
CommandFlags
.
NoCache
);
private
SqlConnection
_marsConnection
;
private
SqlConnection
MarsConnection
=>
_marsConnection
??
(
_marsConnection
=
GetOpenConnection
(
true
));
int
c
,
d
;
SqlMapper
.
PurgeQueryCache
();
int
before
=
SqlMapper
.
GetCachedSQLCount
();
using
(
var
multi
=
MarsConnection
.
QueryMultiple
(
cmdDef
))
[
Fact
]
public
void
AssertNoCacheWorksForQueryMultiple
()
{
c
=
multi
.
Read
<
int
>().
Single
();
d
=
multi
.
Read
<
int
>().
Single
();
const
int
a
=
123
,
b
=
456
;
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
...
...
Dapper.Tests/ConstructorTests.cs
View file @
9076086b
...
...
@@ -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
abstract
class
Order
...
...
Dapper.Tests/Dapper.Tests.csproj
View file @
9076086b
...
...
@@ -6,14 +6,13 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net452;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<DefineConstants>$(DefineConstants);NET45;MYSQL;ENTITY_FRAMEWORK;LINQ2SQL;FIREBIRD;SQL_CE;POSTGRESQL;OLEDB;SQLITE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);COREFX</DefineConstants>
<DefineConstants>$(DefineConstants);ENTITY_FRAMEWORK;LINQ2SQL;SQL_CE;OLEDB</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Remove="Test.DB.sdf" />
...
...
@@ -21,23 +20,22 @@
<ItemGroup>
<ProjectReference Include="..\Dapper\Dapper.csproj" />
<ProjectReference Include="..\Dapper.Contrib\Dapper.Contrib.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="MySql.Data" Version="8.0.8-dmr" />
<PackageReference Include="Npgsql" Version="3.2.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<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 Condition="
'$(TargetFramework)' == 'net452'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net452'
">
<ProjectReference Include="..\Dapper.EntityFramework\Dapper.EntityFramework.csproj" />
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.8.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<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.Data" />
<Reference Include="System.Data.Linq" />
...
...
@@ -47,9 +45,12 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.Ben" Version="1.0.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="1.1.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
...
...
Dapper.Tests/DataReaderTests.cs
View file @
9076086b
...
...
@@ -4,7 +4,7 @@
namespace
Dapper.Tests
{
public
partial
class
DataReaderTests
:
TestBase
public
class
DataReaderTests
:
TestBase
{
[
Fact
]
public
void
GetSameReaderForSameShape
()
...
...
@@ -137,18 +137,13 @@ private abstract class Discriminated_BaseType
private
class
Discriminated_Foo
:
Discriminated_BaseType
{
public
string
Name
{
get
;
set
;
}
public
override
int
Type
{
get
{
return
1
;
}
}
public
override
int
Type
=>
1
;
}
private
class
Discriminated_Bar
:
Discriminated_BaseType
{
public
float
Value
{
get
;
set
;
}
public
override
int
Type
{
get
{
return
2
;
}
}
public
override
int
Type
=>
2
;
}
private
abstract
class
DiscriminatedWithMultiMapping_BaseType
:
Discriminated_BaseType
...
...
@@ -160,20 +155,14 @@ private class DiscriminatedWithMultiMapping_Foo : DiscriminatedWithMultiMapping_
{
public
override
HazNameId
HazNameIdObject
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
override
int
Type
{
get
{
return
1
;
}
}
public
override
int
Type
=>
1
;
}
private
class
DiscriminatedWithMultiMapping_Bar
:
DiscriminatedWithMultiMapping_BaseType
{
public
override
HazNameId
HazNameIdObject
{
get
;
set
;
}
public
float
Value
{
get
;
set
;
}
public
override
int
Type
{
get
{
return
2
;
}
}
public
override
int
Type
=>
2
;
}
}
}
\ No newline at end of file
Dapper.Tests/DecimalTests.cs
View file @
9076086b
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Xunit
;
namespace
Dapper.Tests
...
...
Dapper.Tests/Helpers/Attributes.cs
View file @
9076086b
...
...
@@ -4,20 +4,6 @@
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
)]
public
sealed
class
FactLongRunningAttribute
:
FactAttribute
{
...
...
Dapper.Tests/MiscTests.cs
View file @
9076086b
...
...
@@ -8,7 +8,7 @@
using
System.Linq
;
using
Xunit
;
#if
COREFX
#if
NETCOREAPP1_0
using
System.Collections
;
using
System.Dynamic
;
using
System.Data.SqlTypes
;
...
...
@@ -18,7 +18,7 @@
using
System.Threading.Tasks
;
#endif
#if
COREFX
#if
NETCOREAPP1_0
namespace
System
{
public
enum
GenericUriParserOptions
...
...
@@ -507,7 +507,7 @@ public void TestInheritance()
list
.
First
().
Base2
.
IsEqualTo
(
"Four"
);
}
#if !
COREFX
#if !
NETCOREAPP1_0
[
Fact
]
public
void
ExecuteReader
()
{
...
...
Dapper.Tests/NullTests.cs
View file @
9076086b
...
...
@@ -2,6 +2,7 @@
using
System.Linq
;
namespace
Dapper.Tests
{
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
NullTests
:
TestBase
{
[
Fact
]
...
...
Dapper.Tests/ParameterTests.cs
View file @
9076086b
...
...
@@ -10,6 +10,7 @@
using
Xunit
;
using
System.Globalization
;
using
System.Text.RegularExpressions
;
using
System.Diagnostics
;
#if ENTITY_FRAMEWORK
using
System.Data.Entity.Spatial
;
...
...
@@ -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
readonly
IEnumerable
<
int
>
numbers
;
...
...
@@ -50,19 +69,8 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var
sqlCommand
=
(
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
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.
}
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
"ints"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
...
...
@@ -84,19 +92,8 @@ public void AddParameter(IDbCommand command, string name)
var
sqlCommand
=
(
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
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.
}
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
name
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
...
...
@@ -217,7 +214,6 @@ public void TestMassiveStrings()
.
IsEqualTo
(
str
);
}
#if !COREFX
[
Fact
]
public
void
TestTVPWithAnonymousObject
()
{
...
...
@@ -288,19 +284,8 @@ public new void AddParameters(IDbCommand command, SqlMapper.Identity identity)
var
sqlCommand
=
(
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
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.
}
var
number_list
=
CreateSqlDataRecordList
(
numbers
);
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
"ints"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
...
...
@@ -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
]
public
void
DataTableParameters
()
{
...
...
@@ -491,7 +553,7 @@ public SO29596645_RuleTableValuedParameters(string parameterName)
public
void
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
{
Console
.
WriteLine
(
"> AddParameters"
);
Debug
.
WriteLine
(
"> AddParameters"
);
var
lazy
=
(
SqlCommand
)
command
;
lazy
.
Parameters
.
AddWithValue
(
"Id"
,
7
);
var
table
=
new
DataTable
...
...
@@ -500,7 +562,7 @@ public void AddParameters(IDbCommand command, SqlMapper.Identity identity)
Rows
=
{
{
4
},
{
9
}
}
};
lazy
.
Parameters
.
AddWithValue
(
"Rules"
,
table
);
Console
.
WriteLine
(
"< AddParameters"
);
Debug
.
WriteLine
(
"< AddParameters"
);
}
}
...
...
Dapper.Tests/ProcedureTests.cs
View file @
9076086b
...
...
@@ -103,7 +103,7 @@ public void SO24605346_ProcsAndStrings()
private
class
PracticeRebateOrders
{
public
string
fTaxInvoiceNumber
;
#if !
COREFX
#if !
NETCOREAPP1_0
[
System
.
Xml
.
Serialization
.
XmlElement
(
Form
=
System
.
Xml
.
Schema
.
XmlSchemaForm
.
Unqualified
)]
#endif
public
string
TaxInvoiceNumber
...
...
Dapper.Tests/Providers/EntityFrameworkTests.cs
View file @
9076086b
...
...
@@ -4,6 +4,7 @@
namespace
Dapper.Tests.Providers
{
[
Collection
(
"TypeHandlerTests"
)]
public
class
EntityFrameworkTests
:
TestBase
{
public
EntityFrameworkTests
()
...
...
Dapper.Tests/Providers/FirebirdTests.cs
View file @
9076086b
#
if
FIREBIRD
using
FirebirdSql.Data.FirebirdClient
;
using
FirebirdSql.Data.FirebirdClient
;
using
System.Data
;
using
System.Linq
;
using
Xunit
;
...
...
@@ -45,5 +44,4 @@ public void Issue178_Firebird()
}
}
}
}
#
endif
\ No newline at end of file
}
\ No newline at end of file
Dapper.Tests/Providers/Linq2SqlTests.cs
View file @
9076086b
...
...
@@ -38,6 +38,27 @@ private class WithBinary
{
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
\ No newline at end of file
Dapper.Tests/Providers/MySQLTests.cs
View file @
9076086b
#
if
MYSQL
using
System
;
using
System
;
using
System.Linq
;
using
Xunit
;
...
...
@@ -186,4 +185,3 @@ static FactMySqlAttribute()
}
}
}
#endif
Dapper.Tests/Providers/PostgresqlTests.cs
View file @
9076086b
#
if
POSTGRESQL
using
System
;
using
System
;
using
System.Data
;
using
System.Linq
;
using
Xunit
;
...
...
@@ -80,5 +79,4 @@ static FactPostgresqlAttribute()
}
}
}
}
#
endif
\ No newline at end of file
}
\ No newline at end of file
Dapper.Tests/Providers/SqliteTests.cs
View file @
9076086b
#
if
SQLITE
using
Microsoft.Data.Sqlite
;
using
System
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Data.SQLite
;
using
System.Data
;
using
Xunit
;
namespace
Dapper.Tests
{
public
class
SqliteTests
:
TestBase
{
protected
static
S
QL
iteConnection
GetSQLiteConnection
(
bool
open
=
true
)
protected
static
S
ql
iteConnection
GetSQLiteConnection
(
bool
open
=
true
)
{
var
connection
=
new
S
QL
iteConnection
(
"Data Source=:memory:"
);
var
connection
=
new
S
ql
iteConnection
(
"Data Source=:memory:"
);
if
(
open
)
connection
.
Open
();
return
connection
;
}
...
...
@@ -26,41 +24,45 @@ public void DapperEnumValue_Sqlite()
}
}
[
FactSqlite
]
public
void
Issue466_SqliteHatesOptimizations
()
[
Collection
(
NonParallelDefinition
.
Name
)
]
public
class
SqliteTypeHandlerTests
:
TestBase
{
using
(
var
connection
=
GetSQLiteConnection
())
[
FactSqlite
]
public
void
Issue466_SqliteHatesOptimizations
()
{
SqlMapper
.
ResetTypeHandlers
();
var
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
row
.
Id
.
IsEqualTo
(
42
);
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
row
.
Id
.
IsEqualTo
(
42
);
using
(
var
connection
=
GetSQLiteConnection
())
{
SqlMapper
.
ResetTypeHandlers
();
var
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
row
.
Id
.
IsEqualTo
(
42
);
row
=
connection
.
Query
<
HazNameId
>(
"select 42 as Id"
).
First
();
row
.
Id
.
IsEqualTo
(
42
);
SqlMapper
.
ResetTypeHandlers
();
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
.
Id
.
IsEqualTo
(
42
);
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
.
Id
.
IsEqualTo
(
42
);
SqlMapper
.
ResetTypeHandlers
();
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
.
Id
.
IsEqualTo
(
42
);
row
=
connection
.
QueryFirst
<
HazNameId
>(
"select 42 as Id"
);
row
.
Id
.
IsEqualTo
(
42
);
}
}
}
[
FactSqlite
]
public
async
Task
Issue466_SqliteHatesOptimizations_Async
()
{
using
(
var
connection
=
GetSQLiteConnection
())
[
FactSqlite
]
public
async
Task
Issue466_SqliteHatesOptimizations_Async
()
{
SqlMapper
.
ResetTypeHandlers
();
var
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
row
.
Id
.
IsEqualTo
(
42
);
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
row
.
Id
.
IsEqualTo
(
42
);
using
(
var
connection
=
GetSQLiteConnection
())
{
SqlMapper
.
ResetTypeHandlers
();
var
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
row
.
Id
.
IsEqualTo
(
42
);
row
=
(
await
connection
.
QueryAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
)).
First
();
row
.
Id
.
IsEqualTo
(
42
);
SqlMapper
.
ResetTypeHandlers
();
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
row
.
Id
.
IsEqualTo
(
42
);
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
row
.
Id
.
IsEqualTo
(
42
);
SqlMapper
.
ResetTypeHandlers
();
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
row
.
Id
.
IsEqualTo
(
42
);
row
=
await
connection
.
QueryFirstAsync
<
HazNameId
>(
"select 42 as Id"
).
ConfigureAwait
(
false
);
row
.
Id
.
IsEqualTo
(
42
);
}
}
}
...
...
@@ -82,11 +84,7 @@ private void Isse467_SqliteParameterNaming(bool prefix)
{
var
cmd
=
connection
.
CreateCommand
();
cmd
.
CommandText
=
"select @foo"
;
#if NET45
const
DbType
type
=
DbType
.
Int32
;
#else
const
SqliteType
type
=
SqliteType
.
Integer
;
#endif
cmd
.
Parameters
.
Add
(
prefix
?
"@foo"
:
"foo"
,
type
).
Value
=
42
;
var
i
=
Convert
.
ToInt32
(
cmd
.
ExecuteScalar
());
i
.
IsEqualTo
(
42
);
...
...
@@ -118,5 +116,4 @@ static FactSqliteAttribute()
}
}
}
}
#
endif
\ No newline at end of file
}
\ No newline at end of file
Dapper.Tests/TestBase.cs
View file @
9076086b
...
...
@@ -2,7 +2,8 @@
using
System.Data
;
using
System.Data.SqlClient
;
using
System.Globalization
;
#if !COREFX
using
Xunit
;
#if !NETCOREAPP1_0
using
System.Threading
;
#endif
...
...
@@ -45,7 +46,7 @@ public SqlConnection GetClosedConnection()
protected
static
CultureInfo
ActiveCulture
{
#if
COREFX
#if
NETCOREAPP1_0
get
{
return
CultureInfo
.
CurrentCulture
;
}
set
{
CultureInfo
.
CurrentCulture
=
value
;
}
#else
...
...
@@ -58,8 +59,8 @@ static TestBase()
{
Console
.
WriteLine
(
"Dapper: "
+
typeof
(
SqlMapper
).
AssemblyQualifiedName
);
Console
.
WriteLine
(
"Using Connectionstring: {0}"
,
ConnectionString
);
#if
COREFX
Console
.
WriteLine
(
"CoreCLR"
);
#if
NETCOREAPP1_0
Console
.
WriteLine
(
"CoreCLR
(netcoreapp1.0)
"
);
#else
Console
.
WriteLine
(
".NET: "
+
Environment
.
Version
);
Console
.
Write
(
"Loading native assemblies for SQL types..."
);
...
...
@@ -81,4 +82,10 @@ public void Dispose()
_connection
?.
Dispose
();
}
}
[
CollectionDefinition
(
Name
,
DisableParallelization
=
true
)]
public
class
NonParallelDefinition
:
TestBase
{
public
const
string
Name
=
"NonParallel"
;
}
}
Dapper.Tests/TypeHandlerTests.cs
View file @
9076086b
...
...
@@ -8,6 +8,7 @@
namespace
Dapper.Tests
{
[
Collection
(
NonParallelDefinition
.
Name
)]
public
class
TypeHandlerTests
:
TestBase
{
[
Fact
]
...
...
@@ -48,6 +49,51 @@ public void TestChangingDefaultStringTypeMappingToAnsiStringFirstOrDefault()
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
]
public
void
Issue136_ValueTypeHandlers
()
{
...
...
@@ -230,52 +276,52 @@ private void TestBigIntForEverythingWorks_ByDataType<T>(string dbType)
row
.
N_P_Long
.
Value
.
IsEqualTo
(
LotsOfNumerics
.
E_Long
.
B
);
row
.
N_P_ULong
.
Value
.
IsEqualTo
(
LotsOfNumerics
.
E_ULong
.
B
);
TestBigIntForEverythingWorks
<
bool
>(
true
,
dbType
);
TestBigIntForEverythingWorks
<
sbyte
>((
sbyte
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
byte
>((
byte
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
int
>((
int
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
uint
>((
uint
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
short
>((
short
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
ushort
>((
ushort
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
long
>((
long
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
ulong
>((
ulong
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
float
>((
float
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
double
>((
double
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
decimal
>((
decimal
)
1
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_Byte
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_SByte
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_Int
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_UInt
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_Short
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_UShort
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_Long
.
B
,
dbType
);
TestBigIntForEverythingWorks
(
LotsOfNumerics
.
E_ULong
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
bool
?>(
true
,
dbType
);
TestBigIntForEverythingWorks
<
sbyte
?>((
sbyte
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
byte
?>((
byte
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
int
?>((
int
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
uint
?>((
uint
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
short
?>((
short
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
ushort
?>((
ushort
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
long
?>((
long
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
ulong
?>((
ulong
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
float
?>((
float
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
double
?>((
double
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
decimal
?>((
decimal
)
1
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_Byte
?>(
LotsOfNumerics
.
E_Byte
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_SByte
?>(
LotsOfNumerics
.
E_SByte
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_Int
?>(
LotsOfNumerics
.
E_Int
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_UInt
?>(
LotsOfNumerics
.
E_UInt
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_Short
?>(
LotsOfNumerics
.
E_Short
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_UShort
?>(
LotsOfNumerics
.
E_UShort
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_Long
?>(
LotsOfNumerics
.
E_Long
.
B
,
dbType
);
TestBigIntForEverythingWorks
<
LotsOfNumerics
.
E_ULong
?>(
LotsOfNumerics
.
E_ULong
.
B
,
dbType
);
}
private
void
TestBigIntForEverythingWorks
<
T
>(
T
expected
,
string
dbType
)
TestBigIntForEverythingWorks
Generic
<
bool
>(
true
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
sbyte
>((
sbyte
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
byte
>((
byte
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
int
>((
int
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
uint
>((
uint
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
short
>((
short
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
ushort
>((
ushort
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
long
>((
long
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
ulong
>((
ulong
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
float
>((
float
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
double
>((
double
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
decimal
>((
decimal
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_Byte
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_SByte
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_Int
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_UInt
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_Short
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_UShort
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_Long
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
(
LotsOfNumerics
.
E_ULong
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
bool
?>(
true
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
sbyte
?>((
sbyte
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
byte
?>((
byte
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
int
?>((
int
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
uint
?>((
uint
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
short
?>((
short
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
ushort
?>((
ushort
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
long
?>((
long
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
ulong
?>((
ulong
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
float
?>((
float
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
double
?>((
double
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
decimal
?>((
decimal
)
1
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_Byte
?>(
LotsOfNumerics
.
E_Byte
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_SByte
?>(
LotsOfNumerics
.
E_SByte
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_Int
?>(
LotsOfNumerics
.
E_Int
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_UInt
?>(
LotsOfNumerics
.
E_UInt
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_Short
?>(
LotsOfNumerics
.
E_Short
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_UShort
?>(
LotsOfNumerics
.
E_UShort
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_Long
?>(
LotsOfNumerics
.
E_Long
.
B
,
dbType
);
TestBigIntForEverythingWorks
Generic
<
LotsOfNumerics
.
E_ULong
?>(
LotsOfNumerics
.
E_ULong
.
B
,
dbType
);
}
private
void
TestBigIntForEverythingWorks
Generic
<
T
>(
T
expected
,
string
dbType
)
{
var
query
=
connection
.
Query
<
T
>(
"select cast(1 as "
+
dbType
+
")"
).
Single
();
query
.
IsEqualTo
(
expected
);
...
...
@@ -462,7 +508,7 @@ public void Test_RemoveTypeMap()
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"
);
dateTimeHandler
.
ParseWasCalled
.
IsTrue
();
...
...
@@ -518,51 +564,6 @@ private class ResultsChangeType
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
int
A
{
get
;
set
;
}
...
...
@@ -634,7 +635,7 @@ public void Issue149_TypeMismatch_SequentialAccess()
Guid
guid
=
Guid
.
Parse
(
"cf0ef7ac-b6fe-4e24-aeda-a2b45bb5654e"
);
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
;
}
catch
(
Exception
ex
)
...
...
@@ -658,5 +659,84 @@ public void SO29343103_UtcDates()
var
delta
=
returned
-
date
;
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
;
}
}
}
}
Dapper.sln
View file @
9076086b
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26
403.7
VisualStudioVersion = 15.0.26
730.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A34907DF-958A-4E4C-8491-84CF303FD13E}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
build.sh = build.sh
Directory.build.props = Directory.build.props
License.txt = License.txt
nuget.config = nuget.config
Readme.md = Readme.md
semver.txt = semver.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Dapper\Dapper.csproj", "{FAC24C3F-68F9-4247-A4B9-21D487E99275}"
...
...
@@ -101,4 +103,7 @@ Global
{39D3EEB6-9C05-4F4A-8C01-7B209742A7EB} = {4E956F6B-6BD8-46F5-BC85-49292FF8F9AB}
{F017075A-2969-4A8E-8971-26F154EB420F} = {568BD46C-1C65-4D44-870C-12CD72563262}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {928A4226-96F3-409A-8A83-9E7444488710}
EndGlobalSection
EndGlobal
Dapper/Dapper.csproj
View file @
9076086b
...
...
@@ -5,9 +5,9 @@
<Title>Dapper</Title>
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc..</Description>
<Authors>Sam Saffron;Marc Gravell;Nick Craver</Authors>
<TargetFrameworks>net4
0;net45;net451;netstandard1.3
</TargetFrameworks>
<TargetFrameworks>net4
51;netstandard1.3;netstandard2.0
</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="
'$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net451'
">
<ItemGroup Condition="
'$(TargetFramework)' == 'net451'
">
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
...
...
@@ -17,7 +17,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Collections.Concurrent" 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.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
...
...
@@ -25,4 +25,9 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
</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>
Dapper/DataTableHandler.cs
View file @
9076086b
using
System
;
using
System.Data
;
#if !
COREFX
#if !
NETSTANDARD1_3
namespace
Dapper
{
internal
sealed
class
DataTableHandler
:
SqlMapper
.
ITypeHandler
...
...
Dapper/DefaultTypeMap.cs
View file @
9076086b
...
...
@@ -26,7 +26,7 @@ public DefaultTypeMap(Type type)
Properties
=
GetSettableProps
(
type
);
_type
=
type
;
}
#if
COREFX
#if
NETSTANDARD1_3
private
static
bool
IsParameterMatch
(
ParameterInfo
[]
x
,
ParameterInfo
[]
y
)
{
if
(
ReferenceEquals
(
x
,
y
))
return
true
;
...
...
@@ -40,7 +40,7 @@ private static bool IsParameterMatch(ParameterInfo[] x, ParameterInfo[] y)
internal
static
MethodInfo
GetPropertySetter
(
PropertyInfo
propertyInfo
,
Type
type
)
{
if
(
propertyInfo
.
DeclaringType
==
type
)
return
propertyInfo
.
GetSetMethod
(
true
);
#if
COREFX
#if
NETSTANDARD1_3
return
propertyInfo
.
DeclaringType
.
GetProperties
(
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
)
.
Single
(
x
=>
x
.
Name
==
propertyInfo
.
Name
&&
x
.
PropertyType
==
propertyInfo
.
PropertyType
...
...
@@ -118,7 +118,7 @@ public ConstructorInfo FindConstructor(string[] names, Type[] types)
public
ConstructorInfo
FindExplicitConstructor
()
{
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
();
#else
var
withAttr
=
constructors
.
Where
(
c
=>
c
.
GetCustomAttributes
(
typeof
(
ExplicitConstructorAttribute
),
true
).
Length
>
0
).
ToList
();
...
...
Dapper/DynamicParameters.cs
View file @
9076086b
...
...
@@ -6,7 +6,7 @@
using
System.Reflection
;
using
System.Reflection.Emit
;
#if
COREFX
#if
NETSTANDARD1_3
using
ApplicationException
=
System
.
InvalidOperationException
;
#endif
...
...
Dapper/SqlDataRecordHandler.cs
View file @
9076086b
...
...
@@ -2,7 +2,6 @@
using
System.Collections.Generic
;
using
System.Data
;
#if !COREFX
namespace
Dapper
{
internal
sealed
class
SqlDataRecordHandler
:
SqlMapper
.
ITypeHandler
...
...
@@ -18,4 +17,3 @@ public void SetValue(IDbDataParameter parameter, object value)
}
}
}
#
endif
\ No newline at end of file
Dapper/SqlDataRecordListTVPParameter.cs
View file @
9076086b
using
System
;
using
System.Collections.Generic
;
using
System.Data
;
using
System.Reflection
;
#if !COREFX
namespace
Dapper
{
/// <summary>
...
...
@@ -23,18 +22,6 @@ public SqlDataRecordListTVPParameter(IEnumerable<Microsoft.SqlServer.Server.SqlD
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
)
{
var
param
=
command
.
CreateParameter
();
...
...
@@ -54,4 +41,3 @@ internal static void Set(IDbDataParameter parameter, IEnumerable<Microsoft.SqlSe
}
}
}
#
endif
\ No newline at end of file
Dapper/SqlMapper.TypeHandlerCache.cs
View file @
9076086b
...
...
@@ -11,7 +11,7 @@ public static partial class SqlMapper
/// </summary>
/// <typeparam name="T">The type to have a cache for.</typeparam>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
Dapper/SqlMapper.cs
View file @
9076086b
...
...
@@ -19,7 +19,7 @@
using
System.Xml
;
using
System.Xml.Linq
;
#if
COREFX
#if
NETSTANDARD1_3
using
DataException
=
System
.
InvalidOperationException
;
#endif
...
...
@@ -217,26 +217,24 @@ static SqlMapper()
private
static
void
ResetTypeHandlers
(
bool
clone
)
{
typeHandlers
=
new
Dictionary
<
Type
,
ITypeHandler
>();
#if !
COREFX
#if !
NETSTANDARD1_3
AddTypeHandlerImpl
(
typeof
(
DataTable
),
new
DataTableHandler
(),
clone
);
#endif
try
{
AddSqlDataRecordsTypeHandler
(
clone
);
}
catch
{
/* https://github.com/StackExchange/dapper-dot-net/issues/424 */
}
#endif
AddTypeHandlerImpl
(
typeof
(
XmlDocument
),
new
XmlDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XDocument
),
new
XDocumentHandler
(),
clone
);
AddTypeHandlerImpl
(
typeof
(
XElement
),
new
XElementHandler
(),
clone
);
}
#if !COREFX
[
MethodImpl
(
MethodImplOptions
.
NoInlining
)]
private
static
void
AddSqlDataRecordsTypeHandler
(
bool
clone
)
{
AddTypeHandlerImpl
(
typeof
(
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>),
new
SqlDataRecordHandler
(),
clone
);
}
#endif
/// <summary>
/// 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
/// </summary>
/// <param name="value">The object to get a corresponding database type for.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -367,7 +365,7 @@ public static DbType GetDbType(object value)
/// <param name="demand">Whether to demand a value (throw if missing).</param>
/// <param name="handler">The handler for <paramref name="type"/>.</param>
[
Obsolete
(
ObsoleteInternalUsageOnly
,
false
)]
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -397,7 +395,7 @@ public static DbType LookupDbType(Type type, string name, bool demand, out IType
return
DynamicParameters
.
EnumerableMultiParameter
;
}
#if !
COREFX
#if !
NETSTANDARD1_3 && !NETSTANDARD2_0
switch
(
type
.
FullName
)
{
case
"Microsoft.SqlServer.Types.SqlGeography"
:
...
...
@@ -1864,7 +1862,7 @@ private static Exception MultiMapException(IDataRecord reader)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -1881,7 +1879,7 @@ public static char ReadChar(object value)
/// Internal use only.
/// </summary>
/// <param name="value">The object to convert to a character.</param>
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -1900,7 +1898,7 @@ public static char ReadChar(object value)
/// <param name="parameters">The parameter collection to search in.</param>
/// <param name="command">The command for this fetch.</param>
/// <param name="name">The name of the parameter to get.</param>
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -1958,7 +1956,7 @@ internal static int GetListPaddingExtraCount(int count)
/// <param name="command">The command to pack parameters for.</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>
#if !
COREFX
#if !
NETSTANDARD1_3
[
Browsable
(
false
)]
#endif
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
...
...
@@ -2257,7 +2255,7 @@ public static string Format(object value)
{
switch
(
TypeExtensions
.
GetTypeCode
(
value
.
GetType
()))
{
#if !
COREFX
#if !
NETSTANDARD1_3
case
TypeCode
.
DBNull
:
return
"null"
;
#endif
...
...
@@ -3080,7 +3078,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
int
index
=
startBound
;
ConstructorInfo
specializedConstructor
=
null
;
#if !
COREFX
#if !
NETSTANDARD1_3
bool
supportInitialize
=
false
;
#endif
Dictionary
<
Type
,
LocalBuilder
>
structLocals
=
null
;
...
...
@@ -3115,7 +3113,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il
.
Emit
(
OpCodes
.
Newobj
,
explicitConstr
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !
COREFX
#if !
NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
...
...
@@ -3137,7 +3135,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
{
il
.
Emit
(
OpCodes
.
Newobj
,
ctor
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
#if !
COREFX
#if !
NETSTANDARD1_3
supportInitialize
=
typeof
(
ISupportInitialize
).
IsAssignableFrom
(
type
);
if
(
supportInitialize
)
{
...
...
@@ -3354,7 +3352,7 @@ private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, Lo
il
.
Emit
(
OpCodes
.
Newobj
,
specializedConstructor
);
}
il
.
Emit
(
OpCodes
.
Stloc_1
);
// stack is empty
#if !
COREFX
#if !
NETSTANDARD1_3
if
(
supportInitialize
)
{
il
.
Emit
(
OpCodes
.
Ldloc_1
);
...
...
@@ -3626,7 +3624,7 @@ public static IEqualityComparer<string> ConnectionStringComparer
private
static
IEqualityComparer
<
string
>
connectionStringComparer
=
StringComparer
.
Ordinal
;
#if !
COREFX
#if !
NETSTANDARD1_3
/// <summary>
/// Key used to indicate the type name associated with a DataTable.
/// </summary>
...
...
@@ -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>
public
static
string
GetTypeName
(
this
DataTable
table
)
=>
table
?.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
#endif
/// <summary>
/// Used to pass a IEnumerable<SqlDataRecord> as a
<see cref="TableValuedParameter"/>
.
/// Used to pass a IEnumerable<SqlDataRecord> as a
TableValuedParameter
.
/// </summary>
/// <param name="list">Th
h
e 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>
public
static
ICustomQueryParameter
AsTableValuedParameter
(
this
IEnumerable
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
list
,
string
typeName
=
null
)
=>
new
SqlDataRecordListTVPParameter
(
list
,
typeName
);
#endif
// one per thread
[
ThreadStatic
]
...
...
Dapper/TableValuedParameter.cs
View file @
9076086b
...
...
@@ -2,7 +2,7 @@
using
System.Data
;
using
System.Reflection
;
#if !
COREFX
#if !
NETSTANDARD1_3
namespace
Dapper
{
/// <summary>
...
...
Dapper/TypeExtensions.cs
View file @
9076086b
...
...
@@ -7,41 +7,41 @@ namespace Dapper
internal
static
class
TypeExtensions
{
public
static
string
Name
(
this
Type
type
)
=>
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
Name
;
#else
type
.
Name
;
#endif
public
static
bool
IsValueType
(
this
Type
type
)
=>
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsValueType
;
#else
type
.
IsValueType
;
#endif
public
static
bool
IsEnum
(
this
Type
type
)
=>
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsEnum
;
#else
type
.
IsEnum
;
#endif
public
static
bool
IsGenericType
(
this
Type
type
)
=>
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsGenericType
;
#else
type
.
IsGenericType
;
#endif
public
static
bool
IsInterface
(
this
Type
type
)
=>
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
type
.
GetTypeInfo
().
IsInterface
;
#else
type
.
IsInterface
;
#endif
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
public
static
IEnumerable
<
Attribute
>
GetCustomAttributes
(
this
Type
type
,
bool
inherit
)
{
return
type
.
GetTypeInfo
().
GetCustomAttributes
(
inherit
);
...
...
@@ -85,7 +85,7 @@ public static TypeCode GetTypeCode(Type type)
public
static
MethodInfo
GetPublicInstanceMethod
(
this
Type
type
,
string
name
,
Type
[]
types
)
{
#if
COREFX
#if
NETSTANDARD1_3 || NETCOREAPP1_0
var
method
=
type
.
GetMethod
(
name
,
types
);
return
(
method
?.
IsPublic
==
true
&&
!
method
.
IsStatic
)
?
method
:
null
;
#else
...
...
Dapper/UdtTypeHandler.cs
View file @
9076086b
...
...
@@ -5,7 +5,7 @@ namespace Dapper
{
public
static
partial
class
SqlMapper
{
#if !
COREFX
#if !
NETSTANDARD1_3 && !NETSTANDARD2_0
/// <summary>
/// A type handler for data-types that are supported by the underlying provider, but which need
/// a well-known UdtTypeName to be specified
...
...
Directory.build.props
View file @
9076086b
...
...
@@ -19,28 +19,20 @@
<DebugType>embedded</DebugType>
<DefaultLanguage>en-US</DefaultLanguage>
<IncludeSymbols>false</IncludeSymbols>
<xUnitVersion>2.3.0-beta5-build3750</xUnitVersion>
</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'">
<Reference Include="System.Core" Pack="false" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)'
== 'net45' OR '$(TargetFramework)' == 'net451
'">
<PropertyGroup Condition=" '$(TargetFramework)'
!= 'net40
'">
<DefineConstants>$(DefineConstants);ASYNC</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);ASYNC;COREFX</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="2.0.2" PrivateAssets="All" />
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="4.3.0-preview1-4045" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.0.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.0.2" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.1.2" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.1.2" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.1.2" />
</ItemGroup>
</Project>
\ No newline at end of file
appveyor.yml
View file @
9076086b
...
...
@@ -52,4 +52,4 @@ deploy:
branch
:
master
api_key
:
secure
:
P/UHxq2DEs0GI1SoDXDesHjRVsSVgdywz5vmsnhFQQY5aJgO3kP+QfhwfhXz19Rw
symbol_server
:
https://www.myget.org/F/stackoverflow/symbols/api/v2/package
\ No newline at end of file
symbol_server
:
https://www.myget.org/F/stackoverflow/symbols/api/v2/package
nuget.config
0 → 100644
View file @
9076086b
<?
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
semver.txt
View file @
9076086b
1.50.3-alpha1
\ No newline at end of file
1.50.4-alpha1
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment