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
a540d7b1
Commit
a540d7b1
authored
Jun 20, 2015
by
johandanforth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #253, use user defined TypeHandlers over internal implementations.
parent
a104524e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+4
-4
Tests.cs
Tests/Tests.cs
+45
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
a540d7b1
...
@@ -910,15 +910,15 @@ internal static DbType LookupDbType(Type type, string name, bool demand, out ITy
...
@@ -910,15 +910,15 @@ internal static DbType LookupDbType(Type type, string name, bool demand, out ITy
{
{
return
DbType
.
Binary
;
return
DbType
.
Binary
;
}
}
if
(
typeHandlers
.
TryGetValue
(
type
,
out
handler
))
{
return
DbType
.
Object
;
}
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
if
(
typeof
(
IEnumerable
).
IsAssignableFrom
(
type
))
{
{
return
DynamicParameters
.
EnumerableMultiParameter
;
return
DynamicParameters
.
EnumerableMultiParameter
;
}
}
if
(
typeHandlers
.
TryGetValue
(
type
,
out
handler
))
{
return
DbType
.
Object
;
}
#if !DNXCORE50
#if !DNXCORE50
switch
(
type
.
FullName
)
switch
(
type
.
FullName
)
{
{
...
...
Tests/Tests.cs
View file @
a540d7b1
...
@@ -3707,6 +3707,51 @@ public void SO24740733_TestCustomValueSingleColumn()
...
@@ -3707,6 +3707,51 @@ public void SO24740733_TestCustomValueSingleColumn()
foo
.
Value
.
IsEqualTo
(
200
);
foo
.
Value
.
IsEqualTo
(
200
);
}
}
public
class
StringListTypeHandler
:
Dapper
.
SqlMapper
.
TypeHandler
<
List
<
String
>>
{
private
StringListTypeHandler
()
{
}
public
static
readonly
StringListTypeHandler
Default
=
new
StringListTypeHandler
();
//Just a simple List<string> type handler implementation
public
override
void
SetValue
(
IDbDataParameter
parameter
,
List
<
string
>
value
)
{
parameter
.
Value
=
String
.
Join
(
","
,
value
);
}
public
override
List
<
string
>
Parse
(
object
value
)
{
return
((
value
as
String
)
??
""
).
Split
(
','
).
ToList
();
}
}
public
class
MyObjectWithStringList
{
public
List
<
String
>
Names
{
get
;
set
;
}
}
public
void
Issue253_TestIEnumerableTypeHandlerParsing
()
{
Dapper
.
SqlMapper
.
ResetTypeHandlers
();
Dapper
.
SqlMapper
.
AddTypeHandler
(
StringListTypeHandler
.
Default
);
var
foo
=
connection
.
Query
<
MyObjectWithStringList
>(
"SELECT 'Sam,Kyro' AS Names"
).
Single
();
foo
.
Names
.
IsSequenceEqualTo
(
new
[]
{
"Sam"
,
"Kyro"
});
}
public
void
Issue253_TestIEnumerableTypeHandlerSetParameterValue
()
{
Dapper
.
SqlMapper
.
ResetTypeHandlers
();
Dapper
.
SqlMapper
.
AddTypeHandler
(
StringListTypeHandler
.
Default
);
connection
.
Execute
(
"CREATE TABLE #Issue253 (Names VARCHAR(50) NOT NULL);"
);
try
{
String
names
=
"Sam,Kyro"
;
List
<
String
>
names_list
=
names
.
Split
(
','
).
ToList
();
var
foo
=
connection
.
Query
<
String
>(
"INSERT INTO #Issue253 (Names) VALUES (@Names); SELECT Names FROM #Issue253;"
,
new
{
Names
=
names_list
}).
Single
();
foo
.
IsEqualTo
(
names
);
}
finally
{
connection
.
Execute
(
"DROP TABLE #Issue253;"
);
}
}
public
void
Issue130_IConvertible
()
public
void
Issue130_IConvertible
()
{
{
dynamic
row
=
connection
.
Query
(
"select 1 as [a], '2' as [b]"
).
Single
();
dynamic
row
=
connection
.
Query
(
"select 1 as [a], '2' as [b]"
).
Single
();
...
...
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