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
63460c60
Commit
63460c60
authored
May 27, 2015
by
johandanforth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
specify sqladapter for insert() and insertasync()
parent
bb5a16ce
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
8 deletions
+32
-8
SqlMapperExtensionsAsync.cs
Dapper.Contrib NET45/SqlMapperExtensionsAsync.cs
+5
-3
TestsAsync.cs
Dapper.Contrib.Tests NET45/TestsAsync.cs
+6
-1
Assert.cs
Dapper.Contrib.Tests/Assert.cs
+8
-0
Tests.cs
Dapper.Contrib.Tests/Tests.cs
+8
-1
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+5
-3
No files found.
Dapper.Contrib NET45/SqlMapperExtensionsAsync.cs
View file @
63460c60
...
...
@@ -129,7 +129,8 @@ public static partial class SqlMapperExtensions
/// <param name="connection">Open SqlConnection</param>
/// <param name="entityToInsert">Entity to insert</param>
/// <returns>Identity of inserted entity</returns>
public
static
async
Task
<
int
>
InsertAsync
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
)
where
T
:
class
public
static
async
Task
<
int
>
InsertAsync
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
ISqlAdapter
sqlAdapter
=
null
)
where
T
:
class
{
var
isList
=
false
;
...
...
@@ -167,8 +168,9 @@ public static partial class SqlMapperExtensions
if
(!
isList
)
//single entity
{
var
adapter
=
GetFormatter
(
connection
);
return
await
adapter
.
InsertAsync
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
if
(
sqlAdapter
==
null
)
sqlAdapter
=
GetFormatter
(
connection
);
return
await
sqlAdapter
.
InsertAsync
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
sbParameterList
.
ToString
(),
keyProperties
,
entityToInsert
);
}
...
...
Dapper.Contrib.Tests NET45/TestsAsync.cs
View file @
63460c60
...
...
@@ -6,6 +6,7 @@
using
System.Linq
;
using
System.Reflection
;
using
System.Threading.Tasks
;
using
Dapper
;
using
Dapper.Contrib.Extensions
;
namespace
Dapper.Contrib.Tests
...
...
@@ -85,9 +86,12 @@ public async Task InsertGetUpdateAsync()
(
await
connection
.
QueryAsync
<
User
>(
"select * from Users"
)).
Count
().
IsEqualTo
(
0
);
(
await
connection
.
UpdateAsync
(
notrackedUser
)).
IsEqualTo
(
false
);
//returns false, user not found
(
await
connection
.
InsertAsync
(
new
User
{
Name
=
"Adam"
,
Age
=
10
},
sqlAdapter
:
new
SqlServerAdapter
())).
IsMoreThan
(
0
);
}
}
public
async
Task
InsertCheckKeyAsync
()
{
using
(
var
connection
=
GetOpenConnection
())
...
...
@@ -272,3 +276,4 @@ public async Task DeleteAllAsync()
}
}
}
Dapper.Contrib.Tests/Assert.cs
View file @
63460c60
...
...
@@ -25,6 +25,14 @@ public static void IsMoreThan(this int obj, int other)
}
}
public
static
void
IsMoreThan
(
this
long
obj
,
int
other
)
{
if
(
obj
<
other
)
{
throw
new
ApplicationException
(
string
.
Format
(
"{0} should be larger than {1}"
,
obj
,
other
));
}
}
public
static
void
IsSequenceEqualTo
<
T
>(
this
IEnumerable
<
T
>
obj
,
IEnumerable
<
T
>
other
)
{
if
(!
obj
.
SequenceEqual
(
other
))
...
...
Dapper.Contrib.Tests/Tests.cs
View file @
63460c60
...
...
@@ -2,10 +2,12 @@
using
System.Collections.Generic
;
using
System.Data
;
using
System.Data.SqlServerCe
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Transactions
;
using
Dapper
;
using
Dapper.Contrib.Extensions
;
namespace
Dapper.Contrib.Tests
...
...
@@ -196,9 +198,13 @@ public void InsertGetUpdate()
connection
.
Update
(
notrackedUser
).
IsEqualTo
(
false
);
//returns false, user not found
//insert with custom sqladapter
connection
.
Insert
(
new
User
{
Name
=
"Adam"
,
Age
=
10
},
sqlAdapter
:
new
SqlServerAdapter
()).
IsMoreThan
(
0
);
}
}
public
void
GetAll
()
{
const
int
numberOfEntities
=
100
;
...
...
@@ -342,3 +348,4 @@ public void DeleteAll()
}
}
Dapper.Contrib/SqlMapperExtensions.cs
View file @
63460c60
...
...
@@ -232,7 +232,8 @@ private static string GetTableName(Type type)
/// <param name="connection">Open SqlConnection</param>
/// <param name="entityToInsert">Entity to insert, can be list of entities</param>
/// <returns>Identity of inserted entity, or number of inserted rows if inserting a list</returns>
public
static
long
Insert
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
)
where
T
:
class
public
static
long
Insert
<
T
>(
this
IDbConnection
connection
,
T
entityToInsert
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
ISqlAdapter
sqlAdapter
=
null
)
where
T
:
class
{
var
isList
=
false
;
...
...
@@ -270,8 +271,9 @@ private static string GetTableName(Type type)
if
(!
isList
)
//single entity
{
var
adapter
=
GetFormatter
(
connection
);
return
adapter
.
Insert
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
if
(
sqlAdapter
==
null
)
sqlAdapter
=
GetFormatter
(
connection
);
return
sqlAdapter
.
Insert
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
sbParameterList
.
ToString
(),
keyProperties
,
entityToInsert
);
}
...
...
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