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
e26ee0ab
Commit
e26ee0ab
authored
Jun 25, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exploration into better support for custom type handlers
parent
88766056
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
230 additions
and
14 deletions
+230
-14
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+162
-14
DapperTests NET40.csproj
Tests/DapperTests NET40.csproj
+4
-0
Tests.cs
Tests/Tests.cs
+64
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
e26ee0ab
This diff is collapsed.
Click to expand it.
Tests/DapperTests NET40.csproj
View file @
e26ee0ab
...
...
@@ -68,6 +68,10 @@
<Reference
Include=
"LinFu.DynamicProxy"
>
<HintPath>
NHibernate\LinFu.DynamicProxy.dll
</HintPath>
</Reference>
<Reference
Include=
"Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll
</HintPath>
</Reference>
<Reference
Include=
"Mono.Security"
>
<HintPath>
..\packages\Npgsql.2.0.11\lib\Net40\Mono.Security.dll
</HintPath>
</Reference>
...
...
Tests/Tests.cs
View file @
e26ee0ab
...
...
@@ -15,6 +15,8 @@
using
System.Data.Common
;
using
System.Globalization
;
using
System.Threading
;
using
System.Data.Entity.Spatial
;
using
Microsoft.SqlServer.Types
;
#if POSTGRESQL
using
Npgsql
;
#endif
...
...
@@ -2885,6 +2887,68 @@ public void SupportInit()
obj
.
Flags
.
Equals
(
31
);
}
public
void
GuidIn_SO_24177902
()
{
// invent and populate
Guid
a
=
Guid
.
NewGuid
(),
b
=
Guid
.
NewGuid
(),
c
=
Guid
.
NewGuid
(),
d
=
Guid
.
NewGuid
();
connection
.
Execute
(
"create table #foo (i int, g uniqueidentifier)"
);
connection
.
Execute
(
"insert #foo(i,g) values(@i,@g)"
,
new
[]
{
new
{
i
=
1
,
g
=
a
},
new
{
i
=
2
,
g
=
b
},
new
{
i
=
3
,
g
=
c
},
new
{
i
=
4
,
g
=
d
}});
// check that rows 2&3 yield guids b&c
var
guids
=
connection
.
Query
<
Guid
>(
"select g from #foo where i in (2,3)"
).
ToArray
();
guids
.
Length
.
Equals
(
2
);
guids
.
Contains
(
a
).
Equals
(
false
);
guids
.
Contains
(
b
).
Equals
(
true
);
guids
.
Contains
(
c
).
Equals
(
true
);
guids
.
Contains
(
d
).
Equals
(
false
);
// in query on the guids
var
rows
=
connection
.
Query
(
"select * from #foo where g in @guids order by i"
,
new
{
guids
})
.
Select
(
row
=>
new
{
i
=
(
int
)
row
.
i
,
g
=
(
Guid
)
row
.
g
}).
ToArray
();
rows
.
Length
.
Equals
(
2
);
rows
[
0
].
i
.
Equals
(
2
);
rows
[
0
].
g
.
Equals
(
b
);
rows
[
1
].
i
.
Equals
(
3
);
rows
[
1
].
g
.
Equals
(
c
);
}
class
HazGeo
{
public
int
Id
{
get
;
set
;
}
public
DbGeography
Geo
{
get
;
set
;
}
}
public
void
DBGeography_SO24405645_SO24402424
()
{
global
::
Dapper
.
SqlMapper
.
AddTypeHandler
(
typeof
(
DbGeography
),
new
GeographyMapper
());
connection
.
Execute
(
"create table #Geo (id int, geo geography)"
);
var
obj
=
new
HazGeo
{
Id
=
1
,
Geo
=
DbGeography
.
LineFromText
(
"LINESTRING(-122.360 47.656, -122.343 47.656 )"
,
4326
)
};
connection
.
Execute
(
"insert #Geo(id, geo) values (@Id, @Geo)"
,
obj
);
var
row
=
connection
.
Query
<
HazGeo
>(
"select * from #Geo where id=1"
).
SingleOrDefault
();
row
.
IsNotNull
();
row
.
Id
.
IsEqualTo
(
1
);
row
.
Geo
.
IsNotNull
();
}
class
GeographyMapper
:
Dapper
.
SqlMapper
.
TypeHandler
<
DbGeography
>
{
public
override
void
SetValue
(
IDbDataParameter
parameter
,
DbGeography
value
)
{
parameter
.
Value
=
value
==
null
?
(
object
)
DBNull
.
Value
:
(
object
)
SqlGeography
.
Parse
(
value
.
AsText
());
((
SqlParameter
)
parameter
).
UdtTypeName
=
"GEOGRAPHY"
;
}
public
override
DbGeography
Parse
(
object
value
)
{
return
(
value
==
null
||
value
is
DBNull
)
?
null
:
DbGeography
.
FromText
(
value
.
ToString
());
}
}
class
WithInit
:
ISupportInitialize
{
public
string
Value
{
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