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
79e1e3ab
Commit
79e1e3ab
authored
Sep 15, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the parameter callbacks onto a method that custom implementations can also use
parent
9226076f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
22 deletions
+33
-22
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+26
-15
SqlMapperAsync.cs
Dapper NET45/SqlMapperAsync.cs
+7
-7
No files found.
Dapper NET40/SqlMapper.cs
View file @
79e1e3ab
...
...
@@ -73,11 +73,11 @@ internal static CommandDefinition ForCallback(object parameters)
private
readonly
CommandFlags
flags
;
internal
void
FireOutputCallbacks
()
internal
void
OnCompleted
()
{
if
(
parameters
is
DynamicParameter
s
)
if
(
parameters
is
SqlMapper
.
IParameterCallback
s
)
{
((
DynamicParameters
)
parameters
).
FireOutputCallbacks
();
((
SqlMapper
.
IParameterCallbacks
)
parameters
).
OnCompleted
();
}
}
/// <summary>
...
...
@@ -263,6 +263,17 @@ public interface IParameterLookup : IDynamicParameters
object
this
[
string
name
]
{
get
;
}
}
/// <summary>
/// Extends IDynamicParameters with facitilies for executing callbacks after commands have completed
/// </summary>
public
partial
interface
IParameterCallbacks
:
IDynamicParameters
{
/// <summary>
/// Invoked when the command has executed
/// </summary>
void
OnCompleted
();
}
/// <summary>
/// Implement this interface to pass an arbitrary db specific parameter to Dapper
/// </summary>
...
...
@@ -1251,7 +1262,7 @@ private static int ExecuteImpl(this IDbConnection cnn, ref CommandDefinition com
total
+=
cmd
.
ExecuteNonQuery
();
}
}
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
finally
{
if
(
wasClosed
)
cnn
.
Close
();
...
...
@@ -1532,7 +1543,7 @@ private static IEnumerable<T> QueryImpl<T>(this IDbConnection cnn, CommandDefini
reader
.
Dispose
();
reader
=
null
;
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
finally
{
...
...
@@ -1785,7 +1796,7 @@ partial class DontMap { }
if
(
finalize
)
{
while
(
reader
.
NextResult
())
{
}
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
}
}
...
...
@@ -1856,7 +1867,7 @@ static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn, Comman
if
(
finalize
)
{
while
(
reader
.
NextResult
())
{
}
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
}
}
...
...
@@ -3163,7 +3174,7 @@ private static int ExecuteCommand(IDbConnection cnn, ref CommandDefinition comma
cmd
=
command
.
SetupCommand
(
cnn
,
paramReader
);
if
(
wasClosed
)
cnn
.
Open
();
int
result
=
cmd
.
ExecuteNonQuery
();
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
return
result
;
}
finally
...
...
@@ -3191,7 +3202,7 @@ private static T ExecuteScalarImpl<T>(IDbConnection cnn, ref CommandDefinition c
cmd
=
command
.
SetupCommand
(
cnn
,
paramReader
);
if
(
wasClosed
)
cnn
.
Open
();
result
=
cmd
.
ExecuteScalar
();
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
finally
{
...
...
@@ -3915,12 +3926,12 @@ public partial class GridReader : IDisposable
private
IDbCommand
command
;
private
Identity
identity
;
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
DynamicParameters
dynamicParam
s
)
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
SqlMapper
.
IParameterCallbacks
callback
s
)
{
this
.
command
=
command
;
this
.
reader
=
reader
;
this
.
identity
=
identity
;
this
.
dynamicParams
=
dynamicParam
s
;
this
.
callbacks
=
callback
s
;
}
#if !CSHARP30
...
...
@@ -4127,7 +4138,7 @@ private IEnumerable<T> ReadDeferred<T>(int index, Func<IDataReader, object> dese
}
private
int
gridIndex
,
readCount
;
private
bool
consumed
;
private
DynamicParameters
dynamicParam
s
;
private
SqlMapper
.
IParameterCallbacks
callback
s
;
/// <summary>
/// Has the underlying reader been consumed?
...
...
@@ -4153,7 +4164,7 @@ private void NextResult()
// need for "Cancel" etc
reader
.
Dispose
();
reader
=
null
;
if
(
dynamicParams
!=
null
)
dynamicParams
.
FireOutputCallbacks
();
if
(
callbacks
!=
null
)
callbacks
.
OnCompleted
();
Dispose
();
}
}
...
...
@@ -4214,7 +4225,7 @@ public static string GetTypeName(this DataTable table)
/// <summary>
/// A bag of parameters that can be passed to the Dapper Query and Execute methods
/// </summary>
partial
class
DynamicParameters
:
SqlMapper
.
IDynamicParameters
,
SqlMapper
.
IParameterLookup
partial
class
DynamicParameters
:
SqlMapper
.
IDynamicParameters
,
SqlMapper
.
IParameterLookup
,
SqlMapper
.
IParameterCallbacks
{
internal
const
DbType
EnumerableMultiParameter
=
(
DbType
)(-
1
);
static
Dictionary
<
SqlMapper
.
Identity
,
Action
<
IDbCommand
,
object
>>
paramReaderCache
=
new
Dictionary
<
SqlMapper
.
Identity
,
Action
<
IDbCommand
,
object
>>();
...
...
@@ -4707,7 +4718,7 @@ internal static class CachedOutputSetters<T>
public
static
readonly
Hashtable
Cache
=
new
Hashtable
();
}
internal
void
FireOutputCallbacks
()
void
SqlMapper
.
IParameterCallbacks
.
OnCompleted
()
{
foreach
(
var
param
in
(
from
p
in
parameters
select
p
.
Value
))
{
...
...
Dapper NET45/SqlMapperAsync.cs
View file @
79e1e3ab
...
...
@@ -96,7 +96,7 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
buffer
.
Add
((
T
)
func
(
reader
));
}
while
(
await
reader
.
NextResultAsync
().
ConfigureAwait
(
false
))
{
}
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
return
buffer
;
}
else
...
...
@@ -238,7 +238,7 @@ private static async Task<int> ExecuteMultiImplAsync(IDbConnection cnn, CommandD
}
}
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
finally
{
...
...
@@ -257,7 +257,7 @@ private static async Task<int> ExecuteImplAsync(IDbConnection cnn, CommandDefini
{
if
(
wasClosed
)
await
((
DbConnection
)
cnn
).
OpenAsync
(
command
.
CancellationToken
).
ConfigureAwait
(
false
);
var
result
=
await
cmd
.
ExecuteNonQueryAsync
(
command
.
CancellationToken
).
ConfigureAwait
(
false
);
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
return
result
;
}
finally
...
...
@@ -514,8 +514,8 @@ private static IEnumerable<T> ExecuteReaderSync<T>(IDataReader reader, Func<IDat
yield
return
(
T
)
func
(
reader
);
}
while
(
reader
.
NextResult
())
{
}
if
(
parameters
is
DynamicParameter
s
)
((
DynamicParameters
)
parameters
).
FireOutputCallbacks
();
if
(
parameters
is
SqlMapper
.
IParameterCallback
s
)
((
SqlMapper
.
IParameterCallbacks
)
parameters
).
OnCompleted
();
}
}
...
...
@@ -580,7 +580,7 @@ private async Task NextResultAsync()
// need for "Cancel" etc
reader
.
Dispose
();
reader
=
null
;
if
(
dynamicParams
!=
null
)
dynamicParams
.
FireOutputCallbacks
();
if
(
callbacks
!=
null
)
callbacks
.
OnCompleted
();
Dispose
();
}
}
...
...
@@ -814,7 +814,7 @@ private async static Task<T> ExecuteScalarImplAsync<T>(IDbConnection cnn, Comman
cmd
=
(
DbCommand
)
command
.
SetupCommand
(
cnn
,
paramReader
);
if
(
wasClosed
)
await
((
DbConnection
)
cnn
).
OpenAsync
(
command
.
CancellationToken
).
ConfigureAwait
(
false
);
result
=
await
cmd
.
ExecuteScalarAsync
(
command
.
CancellationToken
).
ConfigureAwait
(
false
);
command
.
FireOutputCallbacks
();
command
.
OnCompleted
();
}
finally
{
...
...
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