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
29171eaa
Commit
29171eaa
authored
Mar 11, 2012
by
Sam
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26 from greygeek/master
Added test for insert updating object's key
parents
726af71d
eed8b6f5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
Tests.cs
Dapper.Contrib.Tests/Tests.cs
+11
-0
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+3
-8
No files found.
Dapper.Contrib.Tests/Tests.cs
View file @
29171eaa
...
...
@@ -104,6 +104,17 @@ public void InsertGetUpdate()
}
}
public
void
InsertCheckKey
()
{
using
(
var
connection
=
GetOpenConnection
())
{
connection
.
Get
<
IUser
>(
3
).
IsNull
();
User
user
=
new
User
{
Name
=
"Adamb"
,
Age
=
10
};
int
id
=
(
int
)
connection
.
Insert
(
user
);
user
.
Id
.
IsEqualTo
(
id
);
}
}
public
void
BuilderSelectClause
()
{
using
(
var
connection
=
GetOpenConnection
())
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
29171eaa
...
...
@@ -486,14 +486,9 @@ public int Insert(IDbConnection connection, IDbTransaction transaction, int? com
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
var
r
=
connection
.
Query
(
"select @@IDENTITY id"
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
int
id
=
0
;
foreach
(
var
p
in
keyProperties
)
{
var
value
=
((
IDictionary
<
string
,
object
>)
r
.
First
())[
p
.
Name
.
ToLower
()];
p
.
SetValue
(
entityToInsert
,
value
,
null
);
if
(
id
==
0
)
id
=
Convert
.
ToInt32
(
value
);
}
int
id
=
(
int
)
r
.
First
().
id
;
if
(
keyProperties
.
Any
())
keyProperties
.
First
().
SetValue
(
entityToInsert
,
id
,
null
);
return
id
;
}
}
...
...
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