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
c7bb6424
Commit
c7bb6424
authored
Jun 25, 2012
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://code.google.com/p/dapper-dot-net/
parents
f63cd8c0
c1155f91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
SqlMapper.cs
Dapper/SqlMapper.cs
+10
-0
Tests.cs
Tests/Tests.cs
+71
-0
No files found.
Dapper/SqlMapper.cs
View file @
c7bb6424
...
...
@@ -2149,6 +2149,16 @@ static string Clean(string name)
}
void
SqlMapper
.
IDynamicParameters
.
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
{
AddParameters
(
command
,
identity
);
}
/// <summary>
/// Add all the parameters needed to the command just before it executes
/// </summary>
/// <param name="command">The raw command prior to execution</param>
/// <param name="identity">Information about the query</param>
protected
void
AddParameters
(
IDbCommand
command
,
SqlMapper
.
Identity
identity
)
{
if
(
templates
!=
null
)
{
...
...
Tests/Tests.cs
View file @
c7bb6424
...
...
@@ -970,6 +970,77 @@ public void TestTVP()
}
}
class
DynamicParameterWithIntTVP
:
Dapper
.
DynamicParameters
,
Dapper
.
SqlMapper
.
IDynamicParameters
{
IEnumerable
<
int
>
numbers
;
public
DynamicParameterWithIntTVP
(
IEnumerable
<
int
>
numbers
)
{
this
.
numbers
=
numbers
;
}
public
new
void
AddParameters
(
IDbCommand
command
,
Dapper
.
SqlMapper
.
Identity
identity
)
{
base
.
AddParameters
(
command
,
identity
);
var
sqlCommand
=
(
SqlCommand
)
command
;
sqlCommand
.
CommandType
=
CommandType
.
StoredProcedure
;
List
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>
number_list
=
new
List
<
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
>();
// Create an SqlMetaData object that describes our table type.
Microsoft
.
SqlServer
.
Server
.
SqlMetaData
[]
tvp_definition
=
{
new
Microsoft
.
SqlServer
.
Server
.
SqlMetaData
(
"n"
,
SqlDbType
.
Int
)
};
foreach
(
int
n
in
numbers
)
{
// Create a new record, using the metadata array above.
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
rec
=
new
Microsoft
.
SqlServer
.
Server
.
SqlDataRecord
(
tvp_definition
);
rec
.
SetInt32
(
0
,
n
);
// Set the value.
number_list
.
Add
(
rec
);
// Add it to the list.
}
// Add the table parameter.
var
p
=
sqlCommand
.
Parameters
.
Add
(
"ints"
,
SqlDbType
.
Structured
);
p
.
Direction
=
ParameterDirection
.
Input
;
p
.
TypeName
=
"int_list_type"
;
p
.
Value
=
number_list
;
}
}
public
void
TestTVPWithAdditionalParams
()
{
try
{
connection
.
Execute
(
"CREATE TYPE int_list_type AS TABLE (n int NOT NULL PRIMARY KEY)"
);
connection
.
Execute
(
"CREATE PROC get_values @ints int_list_type READONLY, @stringParam varchar(20), @dateParam datetime AS select i.*, @stringParam as stringParam, @dateParam as dateParam from @ints i"
);
var
dynamicParameters
=
new
DynamicParameterWithIntTVP
(
new
int
[]
{
1
,
2
,
3
});
dynamicParameters
.
AddDynamicParams
(
new
{
stringParam
=
"stringParam"
,
dateParam
=
new
DateTime
(
2012
,
1
,
1
)
});
var
results
=
connection
.
Query
(
"get_values"
,
dynamicParameters
,
commandType
:
CommandType
.
StoredProcedure
).
ToList
();
results
.
Count
.
IsEqualTo
(
3
);
for
(
int
i
=
0
;
i
<
results
.
Count
;
i
++)
{
var
result
=
results
[
i
];
Assert
.
IsEqualTo
(
i
+
1
,
result
.
n
);
Assert
.
IsEqualTo
(
"stringParam"
,
result
.
stringParam
);
Assert
.
IsEqualTo
(
new
DateTime
(
2012
,
1
,
1
),
result
.
dateParam
);
}
}
finally
{
try
{
connection
.
Execute
(
"DROP PROC get_values"
);
}
finally
{
connection
.
Execute
(
"DROP TYPE int_list_type"
);
}
}
}
class
Parent
{
public
int
Id
{
get
;
set
;
}
...
...
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