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
4ad839b3
Commit
4ad839b3
authored
Apr 01, 2011
by
Sam Saffron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests and fixes
parent
1ea4eb82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
SqlMapper.cs
SqlMapper.cs
+10
-7
Tests.cs
Tests.cs
+18
-1
No files found.
SqlMapper.cs
View file @
4ad839b3
...
...
@@ -20,6 +20,14 @@ static SqlMapper()
typeMap
[
typeof
(
int
)]
=
SqlDbType
.
Int
;
typeMap
[
typeof
(
int
?)]
=
SqlDbType
.
Int
;
typeMap
[
typeof
(
string
)]
=
SqlDbType
.
NVarChar
;
// weird ... I know see: http://msdn.microsoft.com/en-us/library/ms131092.aspx
typeMap
[
typeof
(
double
)]
=
SqlDbType
.
Float
;
typeMap
[
typeof
(
double
?)]
=
SqlDbType
.
Float
;
typeMap
[
typeof
(
bool
)]
=
SqlDbType
.
Bit
;
typeMap
[
typeof
(
bool
?)]
=
SqlDbType
.
Bit
;
typeMap
[
typeof
(
Guid
)]
=
SqlDbType
.
UniqueIdentifier
;
typeMap
[
typeof
(
Guid
?)]
=
SqlDbType
.
UniqueIdentifier
;
typeMap
[
typeof
(
int
[])]
=
SqlDbType
.
Structured
;
...
...
@@ -106,7 +114,7 @@ public static List<T> ExecuteMapperQuery<T>(this SqlConnection cnn, string sql,
object
oDeserializer
;
if
(!
cachedSerializers
.
TryGetValue
(
identity
,
out
oDeserializer
))
{
if
(
typeof
(
T
).
IsClass
)
if
(
typeof
(
T
).
IsClass
&&
typeof
(
T
)
!=
typeof
(
string
)
)
{
oDeserializer
=
GetClassDeserializer
<
T
>(
reader
);
}
...
...
@@ -210,12 +218,7 @@ private static SqlDataReader GetReader<T>(SqlConnection cnn, SqlTransaction tran
private
static
object
GetStructDeserializer
<
T
>(
SqlDataReader
reader
)
{
Func
<
SqlDataReader
,
T
>
deserializer
=
null
;
var
type
=
typeof
(
T
);
if
(
type
==
typeof
(
int
))
{
// yuck boxing
deserializer
=
r
=>
(
T
)(
object
)
r
.
GetInt32
(
0
);
}
deserializer
=
r
=>
(
T
)
r
.
GetValue
(
0
);
return
deserializer
;
}
...
...
Tests.cs
View file @
4ad839b3
...
...
@@ -45,6 +45,24 @@ public void PassInIntArray()
AssertEquals
(
items
[
2
],
3
);
}
public
void
TestDoubleParam
()
{
AssertEquals
(
connection
.
ExecuteMapperQuery
<
double
>(
"select @d"
,
new
{
d
=
0.1d
}).
First
(),
0.1d
);
}
public
void
TestBoolParam
()
{
AssertEquals
(
connection
.
ExecuteMapperQuery
<
bool
>(
"select @b"
,
new
{
b
=
false
}).
First
(),
false
);
}
public
void
TestStrings
()
{
var
strings
=
connection
.
ExecuteMapperQuery
<
string
>(
@"select 'a' a union select 'b'"
).
ToList
();
AssertEquals
(
strings
[
0
],
"a"
);
AssertEquals
(
strings
[
1
],
"b"
);
}
public
class
Dog
{
public
int
?
Age
{
get
;
set
;
}
...
...
@@ -61,7 +79,6 @@ public void TestIntSupportsNull()
AssertEquals
(
dog
.
Count
(),
1
);
AssertNull
(
dog
.
First
().
Age
);
}
}
}
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