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
fdc7a1ef
Commit
fdc7a1ef
authored
Jun 01, 2011
by
mgravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hybrid parameters for new DynamicParameters(template)
parent
b7245aac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
SqlMapper.cs
Dapper/SqlMapper.cs
+21
-0
Tests.cs
Tests/Tests.cs
+7
-1
No files found.
Dapper/SqlMapper.cs
View file @
fdc7a1ef
...
...
@@ -1194,6 +1194,27 @@ class ParamInfo
public
IDbDataParameter
AttachedParam
{
get
;
set
;
}
}
public
DynamicParameters
()
{
}
public
DynamicParameters
(
object
template
)
{
const
BindingFlags
bindingFlags
=
BindingFlags
.
Public
|
BindingFlags
.
Instance
;
if
(
template
!=
null
)
{
foreach
(
PropertyInfo
prop
in
template
.
GetType
().
GetProperties
(
bindingFlags
))
{
if
(!
prop
.
CanRead
)
continue
;
var
idx
=
prop
.
GetIndexParameters
();
if
(
idx
!=
null
&&
idx
.
Length
!=
0
)
continue
;
Add
(
"@"
+
prop
.
Name
,
prop
.
GetValue
(
template
,
null
),
null
,
ParameterDirection
.
Input
,
null
);
}
foreach
(
FieldInfo
field
in
template
.
GetType
().
GetFields
(
bindingFlags
))
{
Add
(
"@"
+
field
.
Name
,
field
.
GetValue
(
template
),
null
,
ParameterDirection
.
Input
,
null
);
}
}
}
public
void
Add
(
#if CSHARP30
...
...
Tests/Tests.cs
View file @
fdc7a1ef
...
...
@@ -180,7 +180,13 @@ public void TestExecuteCommand()
set nocount on
drop table #t"
,
new
{
a
=
1
,
b
=
2
}).
IsEqualTo
(
2
);
}
public
void
TestExecuteCommandWithHybridParameters
()
{
var
p
=
new
DynamicParameters
(
new
{
a
=
1
,
b
=
2
});
p
.
Add
(
"@c"
,
dbType
:
DbType
.
Int32
,
direction
:
ParameterDirection
.
Output
);
connection
.
Execute
(
@"set @c = @a + @b"
,
p
);
p
.
Get
<
int
>(
"@c"
).
IsEqualTo
(
3
);
}
public
void
TestExecuteMultipleCommand
()
{
connection
.
Execute
(
"create table #t(i int)"
);
...
...
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