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
4aef740a
Commit
4aef740a
authored
Apr 04, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some bugs around list of ints and strings
allos for datetime
parent
bc5bcf50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
SqlMapper.cs
SqlMapper.cs
+23
-5
Tests.cs
Tests.cs
+1
-1
No files found.
SqlMapper.cs
View file @
4aef740a
...
...
@@ -30,10 +30,28 @@ static SqlMapper()
typeMap
[
typeof
(
Guid
)]
=
SqlDbType
.
UniqueIdentifier
;
typeMap
[
typeof
(
Guid
?)]
=
SqlDbType
.
UniqueIdentifier
;
typeMap
[
typeof
(
int
[])]
=
SqlDbType
.
Structured
;
typeMap
[
typeof
(
List
<
int
>)]
=
SqlDbType
.
Structured
;
typeMap
[
typeof
(
string
[])]
=
SqlDbType
.
Structured
;
typeMap
[
typeof
(
List
<
string
>)]
=
SqlDbType
.
Structured
;
typeMap
[
typeof
(
DateTime
)]
=
SqlDbType
.
DateTime
;
typeMap
[
typeof
(
DateTime
?)]
=
SqlDbType
.
DateTime
;
}
private
static
SqlDbType
LookupDbType
(
Type
type
)
{
SqlDbType
dbType
;
if
(
typeMap
.
TryGetValue
(
type
,
out
dbType
))
{
return
dbType
;
}
else
{
if
(
typeof
(
IEnumerable
<
int
>).
IsAssignableFrom
(
type
)
||
typeof
(
IEnumerable
<
string
>).
IsAssignableFrom
(
type
))
{
return
SqlDbType
.
Structured
;
}
}
throw
new
NotSupportedException
(
"The type : "
+
type
.
ToString
()
+
" is not supported by the mapper"
);
}
...
...
@@ -193,7 +211,7 @@ private static object GetDynamicDeserializer(SqlDataReader reader)
il
.
Emit
(
OpCodes
.
Dup
);
// stack is now [list] [list]
il
.
Emit
(
OpCodes
.
Ldstr
,
prop
.
Name
);
// stack is [list] [list] [name]
il
.
Emit
(
OpCodes
.
Ldc_I4
,
(
int
)
typeMap
[
prop
.
PropertyType
]
);
// stack is [list] [list] [name] [dbtype]
il
.
Emit
(
OpCodes
.
Ldc_I4
,
(
int
)
LookupDbType
(
prop
.
PropertyType
)
);
// stack is [list] [list] [name] [dbtype]
il
.
Emit
(
OpCodes
.
Ldloc_0
);
// stack is [list] [list] [name] [dbtype] [typed-param]
il
.
Emit
(
OpCodes
.
Callvirt
,
prop
.
GetGetMethod
());
// stack is [list] [list] [name] [dbtype] [typed-value]
if
(
prop
.
PropertyType
.
IsValueType
)
...
...
Tests.cs
View file @
4aef740a
...
...
@@ -56,7 +56,7 @@ public void SelectListInt()
public
void
PassInIntArray
()
{
connection
.
ExecuteMapperQuery
<
int
>(
"select * from @Ids"
,
new
{
Ids
=
new
int
[]
{
1
,
2
,
3
}
})
connection
.
ExecuteMapperQuery
<
int
>(
"select * from @Ids"
,
new
{
Ids
=
new
int
[]
{
1
,
2
,
3
}
.
AsEnumerable
()
})
.
IsSequenceEqual
(
new
[]
{
1
,
2
,
3
});
}
...
...
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