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
61af54a5
Commit
61af54a5
authored
May 24, 2013
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(via lgsky) - multimap should auto-open/close as necessary
parent
86476bc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+3
-0
Tests.cs
Tests/Tests.cs
+32
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
61af54a5
...
@@ -1073,11 +1073,13 @@ partial class DontMap { }
...
@@ -1073,11 +1073,13 @@ partial class DontMap { }
IDbCommand
ownedCommand
=
null
;
IDbCommand
ownedCommand
=
null
;
IDataReader
ownedReader
=
null
;
IDataReader
ownedReader
=
null
;
bool
wasClosed
=
cnn
.
State
==
ConnectionState
.
Closed
;
try
try
{
{
if
(
reader
==
null
)
if
(
reader
==
null
)
{
{
ownedCommand
=
SetupCommand
(
cnn
,
transaction
,
sql
,
cinfo
.
ParamReader
,
(
object
)
param
,
commandTimeout
,
commandType
);
ownedCommand
=
SetupCommand
(
cnn
,
transaction
,
sql
,
cinfo
.
ParamReader
,
(
object
)
param
,
commandTimeout
,
commandType
);
if
(
wasClosed
)
cnn
.
Open
();
ownedReader
=
ownedCommand
.
ExecuteReader
();
ownedReader
=
ownedCommand
.
ExecuteReader
();
reader
=
ownedReader
;
reader
=
ownedReader
;
}
}
...
@@ -1118,6 +1120,7 @@ partial class DontMap { }
...
@@ -1118,6 +1120,7 @@ partial class DontMap { }
{
{
ownedCommand
.
Dispose
();
ownedCommand
.
Dispose
();
}
}
if
(
wasClosed
)
cnn
.
Close
();
}
}
}
}
}
}
...
...
Tests/Tests.cs
View file @
61af54a5
...
@@ -2186,6 +2186,38 @@ public void ExecuteFromClosed()
...
@@ -2186,6 +2186,38 @@ public void ExecuteFromClosed()
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
}
}
}
}
class
Multi1
{
public
int
Id
{
get
;
set
;
}
}
class
Multi2
{
public
int
Id
{
get
;
set
;
}
}
public
void
QueryMultimapFromClosed
()
{
using
(
var
conn
=
GetClosedConnection
())
{
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
var
i
=
conn
.
Query
<
Multi1
,
Multi2
,
int
>(
"select 2 as [Id], 3 as [Id]"
,
(
x
,
y
)
=>
x
.
Id
+
y
.
Id
).
Single
();
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
i
.
IsEqualTo
(
5
);
}
}
public
void
QueryMultiple2FromClosed
()
{
using
(
var
conn
=
GetClosedConnection
())
{
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
using
(
var
multi
=
conn
.
QueryMultiple
(
"select 1 select 2 select 3"
))
{
multi
.
Read
<
int
>().
Single
().
IsEqualTo
(
1
);
multi
.
Read
<
int
>().
Single
().
IsEqualTo
(
2
);
// not reading 3 is intentional here
}
conn
.
State
.
IsEqualTo
(
ConnectionState
.
Closed
);
}
}
public
void
ExecuteInvalidFromClosed
()
public
void
ExecuteInvalidFromClosed
()
{
{
using
(
var
conn
=
GetClosedConnection
())
using
(
var
conn
=
GetClosedConnection
())
...
...
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