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
7336bfb5
Commit
7336bfb5
authored
Sep 29, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix Issue151: ExpandoObject should work with Execute
parent
5917143e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
+39
-8
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+14
-6
SqlMapperAsync.cs
Dapper NET45/SqlMapperAsync.cs
+2
-2
Tests.cs
Tests/Tests.cs
+23
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
7336bfb5
...
@@ -1236,13 +1236,20 @@ public static T ExecuteScalar<T>(this IDbConnection cnn, CommandDefinition comma
...
@@ -1236,13 +1236,20 @@ public static T ExecuteScalar<T>(this IDbConnection cnn, CommandDefinition comma
return
ExecuteScalarImpl
<
T
>(
cnn
,
ref
command
);
return
ExecuteScalarImpl
<
T
>(
cnn
,
ref
command
);
}
}
private
static
IEnumerable
GetMultiExec
(
object
param
)
{
return
(
param
is
IEnumerable
&&
!(
param
is
string
||
param
is
IEnumerable
<
KeyValuePair
<
string
,
object
>>
))
?
(
IEnumerable
)
param
:
null
;
}
private
static
int
ExecuteImpl
(
this
IDbConnection
cnn
,
ref
CommandDefinition
command
)
private
static
int
ExecuteImpl
(
this
IDbConnection
cnn
,
ref
CommandDefinition
command
)
{
{
object
param
=
command
.
Parameters
;
object
param
=
command
.
Parameters
;
IEnumerable
multiExec
=
param
as
IEnumerable
;
IEnumerable
multiExec
=
GetMultiExec
(
param
)
;
Identity
identity
;
Identity
identity
;
CacheInfo
info
=
null
;
CacheInfo
info
=
null
;
if
(
multiExec
!=
null
&&
!(
multiExec
is
string
)
)
if
(
multiExec
!=
null
)
{
{
#if ASYNC
#if ASYNC
if
((
command
.
Flags
&
CommandFlags
.
Pipelined
)
!=
0
)
if
((
command
.
Flags
&
CommandFlags
.
Pipelined
)
!=
0
)
...
@@ -2845,11 +2852,12 @@ public static string Format(object value)
...
@@ -2845,11 +2852,12 @@ public static string Format(object value)
case
TypeCode
.
Decimal
:
case
TypeCode
.
Decimal
:
return
((
decimal
)
value
).
ToString
(
CultureInfo
.
InvariantCulture
);
return
((
decimal
)
value
).
ToString
(
CultureInfo
.
InvariantCulture
);
default
:
default
:
if
(
value
is
IEnumerable
&&
!(
value
is
string
))
var
multiExec
=
GetMultiExec
(
value
);
if
(
multiExec
!=
null
)
{
{
var
sb
=
new
StringBuilder
();
var
sb
=
new
StringBuilder
();
bool
first
=
true
;
bool
first
=
true
;
foreach
(
object
subval
in
(
IEnumerable
)
value
)
foreach
(
object
subval
in
multiExec
)
{
{
sb
.
Append
(
first
?
'('
:
','
).
Append
(
Format
(
subval
));
sb
.
Append
(
first
?
'('
:
','
).
Append
(
Format
(
subval
));
first
=
false
;
first
=
false
;
...
@@ -3331,10 +3339,10 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
...
@@ -3331,10 +3339,10 @@ private static IDataReader ExecuteReaderImpl(IDbConnection cnn, ref CommandDefin
private
static
Action
<
IDbCommand
,
object
>
GetParameterReader
(
IDbConnection
cnn
,
ref
CommandDefinition
command
)
private
static
Action
<
IDbCommand
,
object
>
GetParameterReader
(
IDbConnection
cnn
,
ref
CommandDefinition
command
)
{
{
object
param
=
command
.
Parameters
;
object
param
=
command
.
Parameters
;
IEnumerable
multiExec
=
(
object
)
param
as
IEnumerable
;
IEnumerable
multiExec
=
GetMultiExec
(
param
)
;
Identity
identity
;
Identity
identity
;
CacheInfo
info
=
null
;
CacheInfo
info
=
null
;
if
(
multiExec
!=
null
&&
!(
multiExec
is
string
)
)
if
(
multiExec
!=
null
)
{
{
throw
new
NotSupportedException
(
"MultiExec is not supported by ExecuteReader"
);
throw
new
NotSupportedException
(
"MultiExec is not supported by ExecuteReader"
);
}
}
...
...
Dapper NET45/SqlMapperAsync.cs
View file @
7336bfb5
...
@@ -132,8 +132,8 @@ public static Task<int> ExecuteAsync(this IDbConnection cnn, string sql, dynamic
...
@@ -132,8 +132,8 @@ public static Task<int> ExecuteAsync(this IDbConnection cnn, string sql, dynamic
public
static
Task
<
int
>
ExecuteAsync
(
this
IDbConnection
cnn
,
CommandDefinition
command
)
public
static
Task
<
int
>
ExecuteAsync
(
this
IDbConnection
cnn
,
CommandDefinition
command
)
{
{
object
param
=
command
.
Parameters
;
object
param
=
command
.
Parameters
;
IEnumerable
multiExec
=
param
as
IEnumerable
;
IEnumerable
multiExec
=
GetMultiExec
(
param
)
;
if
(
multiExec
!=
null
&&
!(
param
is
string
)
)
if
(
multiExec
!=
null
)
{
{
return
ExecuteMultiImplAsync
(
cnn
,
command
,
multiExec
);
return
ExecuteMultiImplAsync
(
cnn
,
command
,
multiExec
);
}
}
...
...
Tests/Tests.cs
View file @
7336bfb5
...
@@ -4018,6 +4018,29 @@ public class Dyno
...
@@ -4018,6 +4018,29 @@ public class Dyno
public
object
Foo
{
get
;
set
;
}
public
object
Foo
{
get
;
set
;
}
}
}
public
void
Issue151_ExpandoObjectArgsQuery
()
{
dynamic
args
=
new
ExpandoObject
();
args
.
Id
=
123
;
args
.
Name
=
"abc"
;
var
row
=
connection
.
Query
(
"select @Id as [Id], @Name as [Name]"
,
(
object
)
args
).
Single
();
((
int
)
row
.
Id
).
Equals
(
123
);
((
string
)
row
.
Name
).
Equals
(
"abc"
);
}
public
void
Issue151_ExpandoObjectArgsExec
()
{
dynamic
args
=
new
ExpandoObject
();
args
.
Id
=
123
;
args
.
Name
=
"abc"
;
connection
.
Execute
(
"create table #issue151 (Id int not null, Name nvarchar(20) not null)"
);
connection
.
Execute
(
"insert #issue151 values(@Id, @Name)"
,
(
object
)
args
).
IsEqualTo
(
1
);
var
row
=
connection
.
Query
(
"select Id, Name from #issue151"
).
Single
();
((
int
)
row
.
Id
).
Equals
(
123
);
((
string
)
row
.
Name
).
Equals
(
"abc"
);
}
#if POSTGRESQL
#if POSTGRESQL
class
Cat
class
Cat
...
...
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