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
148f2f96
Commit
148f2f96
authored
Jul 12, 2012
by
Joao Silva
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dynamic query like for CSharp30. The behavior is simulated with a Dictionary<string,object>
parent
809594cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
2 deletions
+68
-2
SqlMapper.cs
Dapper/SqlMapper.cs
+51
-2
Tests.cs
DapperTests NET35/Tests.cs
+17
-0
No files found.
Dapper/SqlMapper.cs
View file @
148f2f96
...
@@ -625,6 +625,41 @@ public static IEnumerable<dynamic> Query(this IDbConnection cnn, string sql, dyn
...
@@ -625,6 +625,41 @@ public static IEnumerable<dynamic> Query(this IDbConnection cnn, string sql, dyn
{
{
return
Query
<
FastExpando
>(
cnn
,
sql
,
param
as
object
,
transaction
,
buffered
,
commandTimeout
,
commandType
);
return
Query
<
FastExpando
>(
cnn
,
sql
,
param
as
object
,
transaction
,
buffered
,
commandTimeout
,
commandType
);
}
}
#else
/// <summary>
/// Return a list of dynamic objects, reader is closed after the call
/// </summary>
public
static
IEnumerable
<
IDictionary
<
string
,
object
>>
Query
(
this
IDbConnection
cnn
,
string
sql
,
object
param
)
{
return
Query
(
cnn
,
sql
,
param
,
null
,
true
,
null
,
null
);
}
/// <summary>
/// Return a list of dynamic objects, reader is closed after the call
/// </summary>
public
static
IEnumerable
<
IDictionary
<
string
,
object
>>
Query
(
this
IDbConnection
cnn
,
string
sql
,
object
param
,
IDbTransaction
transaction
)
{
return
Query
(
cnn
,
sql
,
param
,
transaction
,
true
,
null
,
null
);
}
/// <summary>
/// Return a list of dynamic objects, reader is closed after the call
/// </summary>
public
static
IEnumerable
<
IDictionary
<
string
,
object
>>
Query
(
this
IDbConnection
cnn
,
string
sql
,
object
param
,
CommandType
?
commandType
)
{
return
Query
(
cnn
,
sql
,
param
,
null
,
true
,
null
,
commandType
);
}
/// <summary>
/// Return a list of dynamic objects, reader is closed after the call
/// </summary>
public
static
IEnumerable
<
IDictionary
<
string
,
object
>>
Query
(
this
IDbConnection
cnn
,
string
sql
,
object
param
,
IDbTransaction
transaction
,
CommandType
?
commandType
)
{
return
Query
(
cnn
,
sql
,
param
,
transaction
,
true
,
null
,
commandType
);
}
/// <summary>
/// Return a list of dynamic objects, reader is closed after the call
/// </summary>
public
static
IEnumerable
<
IDictionary
<
string
,
object
>>
Query
(
this
IDbConnection
cnn
,
string
sql
,
object
param
,
IDbTransaction
transaction
,
bool
buffered
,
int
?
commandTimeout
,
CommandType
?
commandType
)
{
return
Query
<
IDictionary
<
string
,
object
>>(
cnn
,
sql
,
param
,
transaction
,
buffered
,
commandTimeout
,
commandType
);
}
#endif
#endif
/// <summary>
/// <summary>
...
@@ -1016,6 +1051,11 @@ private static CacheInfo GetCacheInfo(Identity identity)
...
@@ -1016,6 +1051,11 @@ private static CacheInfo GetCacheInfo(Identity identity)
{
{
return
GetDynamicDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
return
GetDynamicDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
}
#else
if
(
type
.
IsAssignableFrom
(
typeof
(
Dictionary
<
string
,
object
>)))
{
return
GetDictionaryDeserializer
(
reader
,
startBound
,
length
,
returnNullIfFirstMissing
);
}
#endif
#endif
Type
underlyingType
=
null
;
Type
underlyingType
=
null
;
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
||
type
.
FullName
==
LinqBinary
||
if
(!(
typeMap
.
ContainsKey
(
type
)
||
type
.
IsEnum
||
type
.
FullName
==
LinqBinary
||
...
@@ -1159,9 +1199,14 @@ IEnumerator IEnumerable.GetEnumerator()
...
@@ -1159,9 +1199,14 @@ IEnumerator IEnumerable.GetEnumerator()
#
endregion
#
endregion
}
}
#endif
#if !CSHARP30
private
static
Func
<
IDataReader
,
object
>
GetDynamicDeserializer
(
IDataRecord
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
)
private
static
Func
<
IDataReader
,
object
>
GetDynamicDeserializer
(
IDataRecord
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
)
#else
private
static
Func
<
IDataReader
,
object
>
GetDictionaryDeserializer
(
IDataRecord
reader
,
int
startBound
,
int
length
,
bool
returnNullIfFirstMissing
)
#endif
{
{
var
fieldCount
=
reader
.
FieldCount
;
var
fieldCount
=
reader
.
FieldCount
;
if
(
length
==
-
1
)
if
(
length
==
-
1
)
...
@@ -1188,11 +1233,15 @@ IEnumerator IEnumerable.GetEnumerator()
...
@@ -1188,11 +1233,15 @@ IEnumerator IEnumerable.GetEnumerator()
return
null
;
return
null
;
}
}
}
}
#if !CSHARP30
//we know this is an object so it will not box
//we know this is an object so it will not box
return
FastExpando
.
Attach
(
row
);
return
FastExpando
.
Attach
(
row
);
#else
return
row
;
#endif
};
};
}
}
#endif
/// <summary>
/// <summary>
/// Internal use only
/// Internal use only
/// </summary>
/// </summary>
...
...
DapperTests NET35/Tests.cs
View file @
148f2f96
...
@@ -23,5 +23,22 @@ class BasicType
...
@@ -23,5 +23,22 @@ class BasicType
{
{
public
string
Value
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
}
}
public
void
TestDynamicSimulatedQuery
()
{
var
rows
=
connection
.
Query
(
"select 1 A, 2 B union all select 3, 4"
,
null
).
ToList
();
((
int
)
rows
[
0
][
"A"
])
.
IsEqualTo
(
1
);
((
int
)
rows
[
0
][
"B"
])
.
IsEqualTo
(
2
);
((
int
)
rows
[
1
][
"A"
])
.
IsEqualTo
(
3
);
((
int
)
rows
[
1
][
"B"
])
.
IsEqualTo
(
4
);
}
}
}
}
}
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