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
37dd9468
Commit
37dd9468
authored
Jun 05, 2011
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support enum params and nullable-T params
parent
22f8c33b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
SqlMapper.cs
Dapper/SqlMapper.cs
+7
-0
Tests.cs
Tests/Tests.cs
+21
-0
No files found.
Dapper/SqlMapper.cs
View file @
37dd9468
...
...
@@ -187,6 +187,12 @@ static SqlMapper()
private
static
DbType
LookupDbType
(
Type
type
)
{
DbType
dbType
;
var
nullUnderlyingType
=
Nullable
.
GetUnderlyingType
(
type
);
if
(
nullUnderlyingType
!=
null
)
type
=
nullUnderlyingType
;
if
(
type
.
IsEnum
)
{
type
=
Enum
.
GetUnderlyingType
(
type
);
}
if
(
typeMap
.
TryGetValue
(
type
.
TypeHandle
,
out
dbType
))
{
return
dbType
;
...
...
@@ -197,6 +203,7 @@ private static DbType LookupDbType(Type type)
return
DbType
.
Xml
;
}
throw
new
NotSupportedException
(
string
.
Format
(
"The type : {0} is not supported by dapper"
,
type
));
}
...
...
Tests/Tests.cs
View file @
37dd9468
...
...
@@ -97,6 +97,27 @@ public void TestStrings()
.
IsSequenceEqualTo
(
new
[]
{
"a"
,
"b"
});
}
enum
EnumParam
:
short
{
None
,
A
,
B
}
class
EnumParamObject
{
public
EnumParam
A
{
get
;
set
;
}
public
EnumParam
?
B
{
get
;
set
;
}
public
EnumParam
?
C
{
get
;
set
;
}
}
public
void
TestEnumParams
()
{
EnumParam
a
=
EnumParam
.
A
;
EnumParam
?
b
=
EnumParam
.
B
,
c
=
null
;
var
obj
=
connection
.
Query
<
EnumParamObject
>(
"select @a as A, @b as B, @c as C"
,
new
{
a
,
b
,
c
}).
Single
();
obj
.
A
.
IsEqualTo
(
EnumParam
.
A
);
obj
.
B
.
IsEqualTo
(
EnumParam
.
B
);
obj
.
C
.
IsEqualTo
(
null
);
}
public
class
Dog
{
public
int
?
Age
{
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