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
2706855a
Commit
2706855a
authored
Jun 28, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for weakly typed arrays, aka object array.
parent
ba4795e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
29 deletions
+31
-29
SqlMapper.cs
Dapper/SqlMapper.cs
+22
-29
Tests.cs
Tests/Tests.cs
+9
-0
No files found.
Dapper/SqlMapper.cs
View file @
2706855a
...
@@ -286,41 +286,34 @@ public bool Equals(Identity other)
...
@@ -286,41 +286,34 @@ public bool Equals(Identity other)
{
{
IEnumerable
multiExec
=
(
object
)
param
as
IEnumerable
;
IEnumerable
multiExec
=
(
object
)
param
as
IEnumerable
;
Identity
identity
;
Identity
identity
;
CacheInfo
info
;
CacheInfo
info
=
null
;
if
(
multiExec
!=
null
&&
!(
multiExec
is
string
))
if
(
multiExec
!=
null
&&
!(
multiExec
is
string
))
{
// we actually want a T from IEnumerable<T>
{
var
interfaces
=
multiExec
.
GetType
().
GetInterfaces
();
bool
isFirst
=
true
;
var
openType
=
typeof
(
IEnumerable
<>);
int
total
=
0
;
Type
foundType
=
null
;
using
(
var
cmd
=
SetupCommand
(
cnn
,
transaction
,
sql
,
null
,
null
,
commandTimeout
,
commandType
))
for
(
int
i
=
0
;
i
<
interfaces
.
Length
;
i
++)
{
{
if
(
interfaces
[
i
].
IsGenericType
&&
interfaces
[
i
].
GetGenericTypeDefinition
()
==
openType
)
{
// implementing more than one T is self-inflicted
string
masterSql
=
null
;
foundType
=
interfaces
[
i
].
GetGenericArguments
()[
0
];
foreach
(
var
obj
in
multiExec
)
identity
=
new
Identity
(
sql
,
cnn
,
null
,
foundType
,
null
);
{
info
=
GetCacheInfo
(
identity
);
if
(
isFirst
)
using
(
var
cmd
=
SetupCommand
(
cnn
,
transaction
,
sql
,
null
,
null
,
commandTimeout
,
commandType
))
{
{
bool
isFirst
=
true
;
masterSql
=
cmd
.
CommandText
;
var
masterSql
=
cmd
.
CommandText
;
isFirst
=
false
;
var
reader
=
info
.
ParamReader
;
identity
=
new
Identity
(
sql
,
cnn
,
null
,
obj
.
GetType
(),
null
);
int
total
=
0
;
info
=
GetCacheInfo
(
identity
);
foreach
(
var
obj
in
multiExec
)
{
if
(
isFirst
)
{
isFirst
=
false
;
}
else
{
cmd
.
CommandText
=
masterSql
;
// because we do magic replaces on "in" etc
cmd
.
Parameters
.
Clear
();
// current code is Add-tastic
}
reader
(
cmd
,
obj
);
total
+=
cmd
.
ExecuteNonQuery
();
}
return
total
;
}
}
else
{
cmd
.
CommandText
=
masterSql
;
// because we do magic replaces on "in" etc
cmd
.
Parameters
.
Clear
();
// current code is Add-tastic
}
info
.
ParamReader
(
cmd
,
obj
);
total
+=
cmd
.
ExecuteNonQuery
();
}
}
}
}
return
total
;
}
}
// nice and simple
// nice and simple
...
...
Tests/Tests.cs
View file @
2706855a
...
@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand()
...
@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand()
sum
.
IsEqualTo
(
10
);
sum
.
IsEqualTo
(
10
);
}
}
public
void
TestExecuteMultipleCommandObjectArray
()
{
connection
.
Execute
(
"create table #t(i int)"
);
int
tally
=
connection
.
Execute
(
@"insert #t (i) values(@a)"
,
new
object
[]
{
new
{
a
=
1
},
new
{
a
=
2
},
new
{
a
=
3
},
new
{
a
=
4
}
});
int
sum
=
connection
.
Query
<
int
>(
"select sum(i) from #t drop table #t"
).
First
();
tally
.
IsEqualTo
(
4
);
sum
.
IsEqualTo
(
10
);
}
public
void
TestMassiveStrings
()
public
void
TestMassiveStrings
()
{
{
var
str
=
new
string
(
'X'
,
20000
);
var
str
=
new
string
(
'X'
,
20000
);
...
...
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