2
2
using Microsoft . SqlServer . Types ;
3
3
using NUnit . Framework ;
4
4
using ServiceStack . DataAnnotations ;
5
+ using ServiceStack . Text ;
5
6
6
7
namespace ServiceStack . OrmLite . SqlServerTests . Converters
7
8
{
@@ -13,21 +14,23 @@ public void Can_insert_and_retrieve_SqlGeography()
13
14
{
14
15
using ( var db = OpenDbConnection ( ) )
15
16
{
16
- db . DropAndCreateTable < GeoTestTable > ( ) ;
17
+ db . DropAndCreateTable < GeoTest > ( ) ;
17
18
18
19
// Statue of Liberty
19
- var geo = SqlGeography . Point ( 40.6898329 , - 74.0452177 , 4326 ) ;
20
+ var geo = SqlGeography . Point ( 40.6898329 , - 74.0452177 , 4326 ) ;
20
21
21
- db . Insert ( new GeoTestTable ( ) { Location = geo , NullLocation = SqlGeography . Null } ) ;
22
+ db . Insert ( new GeoTest { Id = 1 , Location = geo , NullLocation = SqlGeography . Null } ) ;
22
23
23
- var result = db . Select ( db . From < GeoTestTable > ( ) ) . First ( ) ;
24
+ var result = db . SingleById < GeoTest > ( 1 ) ;
24
25
25
26
Assert . AreEqual ( geo . Lat , result . Location . Lat ) ;
26
27
Assert . AreEqual ( geo . Long , result . Location . Long ) ;
27
28
Assert . AreEqual ( geo . STSrid , result . Location . STSrid ) ;
28
29
29
30
// Converter always resolves to null even when Null property inserted into database
30
- Assert . AreEqual ( null , result . NullLocation ) ;
31
+ Assert . AreEqual ( null , result . NullLocation ) ;
32
+
33
+ result . PrintDump ( ) ;
31
34
}
32
35
}
33
36
@@ -36,34 +39,59 @@ public void Can_insert_and_retrieve_SqlGeometry()
36
39
{
37
40
using ( var db = OpenDbConnection ( ) )
38
41
{
39
- db . DropAndCreateTable < GeoTestTable > ( ) ;
42
+ db . DropAndCreateTable < GeoTest > ( ) ;
40
43
41
44
// A simple line from (0,0) to (4,4) Length = SQRT(2 * 4^2)
42
45
var wkt = new System . Data . SqlTypes . SqlChars ( "LINESTRING(0 0, 4 4)" . ToCharArray ( ) ) ;
43
46
var shape = SqlGeometry . STLineFromText ( wkt , 0 ) ;
44
47
45
- db . Insert ( new GeoTestTable { Shape = shape } ) ;
48
+ db . Insert ( new GeoTest { Id = 1 , Shape = shape } ) ;
46
49
47
- var result = db . Select ( db . From < GeoTestTable > ( ) ) . First ( ) . Shape ;
50
+ var result = db . SingleById < GeoTest > ( 1 ) . Shape ;
48
51
49
- var lengths = db . Column < double > ( "select Shape.STLength() AS Length from GeoTestTable " ) ;
52
+ var lengths = db . Column < double > ( "select Shape.STLength() AS Length from GeoTest " ) ;
50
53
51
- Assert . AreEqual ( ( double ) result . STLength ( ) , lengths . First ( ) ) ;
54
+ Assert . AreEqual ( ( double ) result . STLength ( ) , lengths . First ( ) ) ;
52
55
53
56
Assert . AreEqual ( shape . STStartPoint ( ) . STX , result . STStartPoint ( ) . STX ) ;
54
57
Assert . AreEqual ( shape . STStartPoint ( ) . STY , result . STStartPoint ( ) . STY ) ;
55
58
56
59
Assert . AreEqual ( shape . STEndPoint ( ) . STX , result . STEndPoint ( ) . STX ) ;
57
60
Assert . AreEqual ( shape . STEndPoint ( ) . STY , result . STEndPoint ( ) . STY ) ;
58
61
59
- Assert . AreEqual ( 2 , ( int ) result . STNumPoints ( ) ) ;
62
+ Assert . AreEqual ( 2 , ( int ) result . STNumPoints ( ) ) ;
63
+
64
+ result . PrintDump ( ) ;
65
+ }
66
+ }
67
+
68
+ [ Test ]
69
+ public void Can_insert_SqlGeography_and_SqlGeometry ( )
70
+ {
71
+ using ( var db = OpenDbConnection ( ) )
72
+ {
73
+ db . DropAndCreateTable < GeoTest > ( ) ;
74
+
75
+ // Statue of Liberty
76
+ var geo = SqlGeography . Point ( 40.6898329 , - 74.0452177 , 4326 ) ;
77
+
78
+ // A simple line from (0,0) to (4,4) Length = SQRT(2 * 4^2)
79
+ var wkt = new System . Data . SqlTypes . SqlChars ( "LINESTRING(0 0, 4 4)" . ToCharArray ( ) ) ;
80
+ var shape = SqlGeometry . STLineFromText ( wkt , 0 ) ;
81
+
82
+ db . Insert ( new GeoTest { Id = 1 , Location = geo , Shape = shape } ) ;
83
+
84
+ var result = db . SingleById < GeoTest > ( 1 ) ;
85
+
86
+ Assert . That ( result , Is . Not . Null ) ;
87
+
88
+ result . PrintDump ( ) ;
60
89
}
61
90
}
62
91
}
63
92
64
- public class GeoTestTable
93
+ public class GeoTest
65
94
{
66
- [ AutoIncrement ]
67
95
public long Id { get ; set ; }
68
96
69
97
public SqlGeography Location { get ; set ; }
0 commit comments