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
aa601bff
Commit
aa601bff
authored
Apr 26, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
e11257fd
182e98a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
39 deletions
+36
-39
SqlMapper.cs
Dapper/SqlMapper.cs
+36
-39
No files found.
Dapper/SqlMapper.cs
View file @
aa601bff
...
...
@@ -178,19 +178,22 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
var
identity
=
new
Identity
(
sql
,
cnn
,
typeof
(
T
),
param
==
null
?
null
:
param
.
GetType
());
var
info
=
GetCacheInfo
(
param
,
identity
);
using
(
var
reader
=
GetReader
(
cnn
,
transaction
,
sql
,
info
.
ParamReader
,
param
))
using
(
var
cmd
=
SetupCommand
(
cnn
,
transaction
,
sql
,
info
.
ParamReader
,
param
))
{
if
(
info
.
Deserializer
==
null
)
{
info
.
Deserializer
=
GetDeserializer
<
T
>(
identity
,
reader
);
queryCache
[
identity
]
=
info
;
}
using
(
var
reader
=
cmd
.
ExecuteReader
())
{
if
(
info
.
Deserializer
==
null
)
{
info
.
Deserializer
=
GetDeserializer
<
T
>(
identity
,
reader
);
queryCache
[
identity
]
=
info
;
}
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
info
.
Deserializer
;
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
info
.
Deserializer
;
while
(
reader
.
Read
())
{
yield
return
deserializer
(
reader
);
while
(
reader
.
Read
())
{
yield
return
deserializer
(
reader
);
}
}
}
}
...
...
@@ -212,20 +215,22 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
var
identity
=
new
Identity
(
sql
,
cnn
,
typeof
(
T
),
param
==
null
?
null
:
param
.
GetType
());
var
info
=
GetCacheInfo
(
param
,
identity
);
using
(
var
reader
=
GetReader
(
cnn
,
transaction
,
sql
,
info
.
ParamReader
,
param
))
using
(
var
cmd
=
SetupCommand
(
cnn
,
transaction
,
sql
,
info
.
ParamReader
,
param
))
{
if
(
info
.
Deserializer
==
null
)
using
(
var
reader
=
cmd
.
ExecuteReader
()
)
{
int
start
=
0
;
int
length
=
-
1
;
for
(
length
=
1
;
length
<
reader
.
FieldCount
;
length
++)
if
(
info
.
Deserializer
==
null
)
{
if
(
reader
.
GetName
(
length
)
==
splitOn
)
int
start
=
0
;
int
length
=
-
1
;
for
(
length
=
1
;
length
<
reader
.
FieldCount
;
length
++)
{
break
;
if
(
reader
.
GetName
(
length
)
==
splitOn
)
{
break
;
}
}
}
// dynamic comes back as object ...
if
(
typeof
(
T
)
==
typeof
(
object
))
...
...
@@ -246,17 +251,18 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
info
.
Deserializer2
=
GetDeserializer
<
U
>(
identity
,
reader
,
start
+
length
,
returnNullIfFirstMissing
:
true
);
}
queryCache
[
identity
]
=
info
;
}
queryCache
[
identity
]
=
info
;
}
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
info
.
Deserializer
;
var
deserializer2
=
(
Func
<
IDataReader
,
U
>)
info
.
Deserializer2
;
var
deserializer
=
(
Func
<
IDataReader
,
T
>)
info
.
Deserializer
;
var
deserializer2
=
(
Func
<
IDataReader
,
U
>)
info
.
Deserializer2
;
while
(
reader
.
Read
())
{
var
tmp
=
deserializer
(
reader
);
map
(
tmp
,
deserializer2
(
reader
));
yield
return
tmp
;
while
(
reader
.
Read
())
{
var
tmp
=
deserializer
(
reader
);
map
(
tmp
,
deserializer2
(
reader
));
yield
return
tmp
;
}
}
}
}
...
...
@@ -504,11 +510,11 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
return
(
Action
<
IDbCommand
,
object
>)
dm
.
CreateDelegate
(
typeof
(
Action
<
IDbCommand
,
object
>));
}
private
static
IDbCommand
SetupCommand
(
IDbConnection
cnn
,
IDbTransaction
tranaction
,
string
sql
,
Action
<
IDbCommand
,
object
>
paramReader
,
object
obj
)
private
static
IDbCommand
SetupCommand
(
IDbConnection
cnn
,
IDbTransaction
tran
s
action
,
string
sql
,
Action
<
IDbCommand
,
object
>
paramReader
,
object
obj
)
{
var
cmd
=
cnn
.
CreateCommand
();
cmd
.
Transaction
=
tranaction
;
cmd
.
Transaction
=
tran
s
action
;
cmd
.
CommandText
=
sql
;
if
(
paramReader
!=
null
)
{
...
...
@@ -526,15 +532,6 @@ private static int ExecuteCommand(IDbConnection cnn, IDbTransaction tranaction,
}
}
private
static
IDataReader
GetReader
(
IDbConnection
cnn
,
IDbTransaction
tranaction
,
string
sql
,
Action
<
IDbCommand
,
object
>
paramReader
,
object
obj
)
{
using
(
var
cmd
=
SetupCommand
(
cnn
,
tranaction
,
sql
,
paramReader
,
obj
))
{
return
cmd
.
ExecuteReader
();
}
}
private
static
object
GetStructDeserializer
<
T
>(
IDataReader
reader
)
{
Func
<
IDataReader
,
T
>
deserializer
=
null
;
...
...
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