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
e408faba
Commit
e408faba
authored
Jun 07, 2015
by
johandanforth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Contrib Insert now handles closed connection
parent
62cb035d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
Tests.cs
Dapper.Contrib.Tests/Tests.cs
+16
-1
SqlMapperExtensions.cs
Dapper.Contrib/SqlMapperExtensions.cs
+15
-5
No files found.
Dapper.Contrib.Tests/Tests.cs
View file @
e408faba
...
...
@@ -96,6 +96,21 @@ public void TestSimpleGet()
connection
.
Delete
(
user
);
}
}
public
void
TestClosedConnection
()
{
//using (var connection = GetOpenConnection())
//{
// connection.Insert(new User { Name = "Adama", Age = 10 }).IsMoreThan(0);
//}
using
(
var
connection
=
GetConnection
())
{
connection
.
Insert
(
new
User
{
Name
=
"Adama"
,
Age
=
10
}).
IsMoreThan
(
0
);
var
users
=
connection
.
GetAll
<
User
>();
users
.
Count
().
IsMoreThan
(
0
);
}
}
public
void
InsertList
()
{
...
...
@@ -208,7 +223,7 @@ public void InsertGetUpdate()
public
void
InsertWithCustomDbType
()
{
SqlMapperExtensions
.
GetDatabaseType
=
conn
ection
=>
"SQLiteConnection"
;
SqlMapperExtensions
.
GetDatabaseType
=
conn
=>
"SQLiteConnection"
;
bool
sqliteCodeCalled
=
false
;
using
(
var
connection
=
GetOpenConnection
())
...
...
Dapper.Contrib/SqlMapperExtensions.cs
View file @
e408faba
...
...
@@ -289,16 +289,24 @@ private static string GetTableName(Type type)
sbParameterList
.
Append
(
", "
);
}
int
returnVal
;
var
wasClosed
=
connection
.
State
==
ConnectionState
.
Closed
;
if
(
wasClosed
)
connection
.
Open
();
if
(!
isList
)
//single entity
{
var
adapter
=
GetFormatter
(
connection
);
return
adapter
.
Insert
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
return
Val
=
adapter
.
Insert
(
connection
,
transaction
,
commandTimeout
,
name
,
sbColumnList
.
ToString
(),
sbParameterList
.
ToString
(),
keyProperties
,
entityToInsert
);
}
//insert list of entities
var
cmd
=
String
.
Format
(
"insert into {0} ({1}) values ({2})"
,
name
,
sbColumnList
,
sbParameterList
);
return
connection
.
Execute
(
cmd
,
entityToInsert
,
transaction
,
commandTimeout
);
else
{
//insert list of entities
var
cmd
=
String
.
Format
(
"insert into {0} ({1}) values ({2})"
,
name
,
sbColumnList
,
sbParameterList
);
returnVal
=
connection
.
Execute
(
cmd
,
entityToInsert
,
transaction
,
commandTimeout
);
}
if
(
wasClosed
)
connection
.
Close
();
return
returnVal
;
}
/// <summary>
...
...
@@ -625,6 +633,8 @@ public partial class SqlServerAdapter : ISqlAdapter
{
public
int
Insert
(
IDbConnection
connection
,
IDbTransaction
transaction
,
int
?
commandTimeout
,
String
tableName
,
string
columnList
,
string
parameterList
,
IEnumerable
<
PropertyInfo
>
keyProperties
,
object
entityToInsert
)
{
//TODO: Append a select identity at end if command?
var
cmd
=
String
.
Format
(
"insert into {0} ({1}) values ({2})"
,
tableName
,
columnList
,
parameterList
);
connection
.
Execute
(
cmd
,
entityToInsert
,
transaction
,
commandTimeout
);
...
...
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