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
5812a2a5
Commit
5812a2a5
authored
May 04, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fast expand is faster :)
parent
1f4f847e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
SqlMapper.cs
Dapper/SqlMapper.cs
+28
-5
No files found.
Dapper/SqlMapper.cs
View file @
5812a2a5
...
@@ -155,7 +155,7 @@ public static int Execute(this IDbConnection cnn, string sql, object param = nul
...
@@ -155,7 +155,7 @@ public static int Execute(this IDbConnection cnn, string sql, object param = nul
/// </summary>
/// </summary>
public
static
IEnumerable
<
dynamic
>
Query
(
this
IDbConnection
cnn
,
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
int
?
commandTimeout
=
null
)
public
static
IEnumerable
<
dynamic
>
Query
(
this
IDbConnection
cnn
,
string
sql
,
dynamic
param
=
null
,
IDbTransaction
transaction
=
null
,
bool
buffered
=
true
,
int
?
commandTimeout
=
null
)
{
{
return
Query
<
ExpandoObject
>(
cnn
,
sql
,
param
as
object
,
transaction
,
buffered
,
commandTimeout
);
return
Query
<
FastExpando
>(
cnn
,
sql
,
param
as
object
,
transaction
,
buffered
,
commandTimeout
);
}
}
...
@@ -385,7 +385,7 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
...
@@ -385,7 +385,7 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
object
oDeserializer
;
object
oDeserializer
;
// dynamic is passed in as Object ... by c# design
// dynamic is passed in as Object ... by c# design
if
(
typeof
(
T
)
==
typeof
(
object
)
||
typeof
(
T
)
==
typeof
(
ExpandoObject
))
if
(
typeof
(
T
)
==
typeof
(
object
)
||
typeof
(
T
)
==
typeof
(
FastExpando
))
{
{
oDeserializer
=
GetDynamicDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
oDeserializer
=
GetDynamicDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
}
...
@@ -402,6 +402,29 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
...
@@ -402,6 +402,29 @@ private static CacheInfo GetCacheInfo(object param, Identity identity)
return
deserializer
;
return
deserializer
;
}
}
private
class
FastExpando
:
DynamicObject
{
IDictionary
<
string
,
object
>
data
;
public
static
FastExpando
Attach
(
IDictionary
<
string
,
object
>
data
)
{
FastExpando
expando
=
new
FastExpando
();
expando
.
data
=
data
;
return
expando
;
}
public
override
bool
TrySetMember
(
SetMemberBinder
binder
,
object
value
)
{
data
[
binder
.
Name
]
=
value
;
return
true
;
}
public
override
bool
TryGetMember
(
GetMemberBinder
binder
,
out
object
result
)
{
return
data
.
TryGetValue
(
binder
.
Name
,
out
result
);
}
}
private
static
object
GetDynamicDeserializer
(
IDataRecord
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
private
static
object
GetDynamicDeserializer
(
IDataRecord
reader
,
int
startBound
=
0
,
int
length
=
-
1
,
bool
returnNullIfFirstMissing
=
false
)
{
{
if
(
length
==
-
1
)
if
(
length
==
-
1
)
...
@@ -409,10 +432,10 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
...
@@ -409,10 +432,10 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
length
=
reader
.
FieldCount
-
startBound
;
length
=
reader
.
FieldCount
-
startBound
;
}
}
Func
<
IDataReader
,
ExpandoObject
>
rval
=
Func
<
IDataReader
,
FastExpando
>
rval
=
r
=>
r
=>
{
{
IDictionary
<
string
,
object
>
row
=
new
ExpandoObject
(
);
IDictionary
<
string
,
object
>
row
=
new
Dictionary
<
string
,
object
>(
length
);
for
(
var
i
=
startBound
;
i
<
startBound
+
length
;
i
++)
for
(
var
i
=
startBound
;
i
<
startBound
+
length
;
i
++)
{
{
var
tmp
=
r
.
GetValue
(
i
);
var
tmp
=
r
.
GetValue
(
i
);
...
@@ -423,7 +446,7 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
...
@@ -423,7 +446,7 @@ private static object GetDynamicDeserializer(IDataRecord reader, int startBound
return
null
;
return
null
;
}
}
}
}
return
(
ExpandoObject
)
row
;
return
FastExpando
.
Attach
(
row
)
;
};
};
return
rval
;
return
rval
;
...
...
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