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
390ba5b4
Commit
390ba5b4
authored
Sep 12, 2011
by
David Chell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made Postgresql specific insert handle entities with no primary keys.
parent
1a506e8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+20
-15
No files found.
Dapper.Contrib/SqlMapperExtensions.cs
View file @
390ba5b4
...
@@ -190,23 +190,28 @@ private static string GetTableName(Type type)
...
@@ -190,23 +190,28 @@ private static string GetTableName(Type type)
sb
.
Append
(
") "
);
sb
.
Append
(
") "
);
long
id
=
0
;
long
id
=
0
;
#if POSTGRESQL
#if POSTGRESQL
sb
.
Append
(
" RETURNING "
);
if
(
keyProperties
.
Count
()
>
0
)
for
(
var
i
=
0
;
i
<
keyProperties
.
Count
();
i
++)
{
{
var
property
=
keyProperties
.
ElementAt
(
i
);
sb
.
Append
(
" RETURNING "
);
sb
.
Append
(
property
.
Name
);
for
(
var
i
=
0
;
i
<
keyProperties
.
Count
();
i
++)
if
(
i
<
keyProperties
.
Count
()
-
1
)
{
sb
.
Append
(
", "
);
var
property
=
keyProperties
.
ElementAt
(
i
);
}
sb
.
Append
(
property
.
Name
);
var
r
=
connection
.
Query
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
if
(
i
<
keyProperties
.
Count
()
-
1
)
// Return the key py assinging the corresponding property in the object - by product is that it supports compound primary keys
sb
.
Append
(
", "
);
foreach
(
var
p
in
keyProperties
)
}
{
var
r
=
connection
.
Query
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
var
value
=
((
IDictionary
<
string
,
object
>)
r
.
First
())[
p
.
Name
.
ToLower
()];
// Return the key py assinging the corresponding property in the object - by product is that it supports compound primary keys
p
.
SetValue
(
entityToInsert
,
value
,
null
);
foreach
(
var
p
in
keyProperties
)
if
(
id
==
0
)
{
id
=
Convert
.
ToInt64
(
value
);
var
value
=
((
IDictionary
<
string
,
object
>)
r
.
First
())[
p
.
Name
.
ToLower
()];
p
.
SetValue
(
entityToInsert
,
value
,
null
);
if
(
id
==
0
)
id
=
Convert
.
ToInt64
(
value
);
}
}
}
else
connection
.
Execute
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
#else
#else
connection
.
Execute
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
connection
.
Execute
(
sb
.
ToString
(),
entityToInsert
,
transaction
:
transaction
,
commandTimeout
:
commandTimeout
);
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
//NOTE: would prefer to use IDENT_CURRENT('tablename') or IDENT_SCOPE but these are not available on SQLCE
...
...
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