22using Microsoft . SqlServer . Types ;
33using NUnit . Framework ;
44using ServiceStack . DataAnnotations ;
5+ using ServiceStack . Text ;
56
67namespace ServiceStack . OrmLite . SqlServerTests . Converters
78{
@@ -13,21 +14,23 @@ public void Can_insert_and_retrieve_SqlGeography()
1314 {
1415 using ( var db = OpenDbConnection ( ) )
1516 {
16- db . DropAndCreateTable < GeoTestTable > ( ) ;
17+ db . DropAndCreateTable < GeoTest > ( ) ;
1718
1819 // Statue of Liberty
19- var geo = SqlGeography . Point ( 40.6898329 , - 74.0452177 , 4326 ) ;
20+ var geo = SqlGeography . Point ( 40.6898329 , - 74.0452177 , 4326 ) ;
2021
21- db . Insert ( new GeoTestTable ( ) { Location = geo , NullLocation = SqlGeography . Null } ) ;
22+ db . Insert ( new GeoTest { Id = 1 , Location = geo , NullLocation = SqlGeography . Null } ) ;
2223
23- var result = db . Select ( db . From < GeoTestTable > ( ) ) . First ( ) ;
24+ var result = db . SingleById < GeoTest > ( 1 ) ;
2425
2526 Assert . AreEqual ( geo . Lat , result . Location . Lat ) ;
2627 Assert . AreEqual ( geo . Long , result . Location . Long ) ;
2728 Assert . AreEqual ( geo . STSrid , result . Location . STSrid ) ;
2829
2930 // 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 ( ) ;
3134 }
3235 }
3336
@@ -36,34 +39,59 @@ public void Can_insert_and_retrieve_SqlGeometry()
3639 {
3740 using ( var db = OpenDbConnection ( ) )
3841 {
39- db . DropAndCreateTable < GeoTestTable > ( ) ;
42+ db . DropAndCreateTable < GeoTest > ( ) ;
4043
4144 // A simple line from (0,0) to (4,4) Length = SQRT(2 * 4^2)
4245 var wkt = new System . Data . SqlTypes . SqlChars ( "LINESTRING(0 0, 4 4)" . ToCharArray ( ) ) ;
4346 var shape = SqlGeometry . STLineFromText ( wkt , 0 ) ;
4447
45- db . Insert ( new GeoTestTable { Shape = shape } ) ;
48+ db . Insert ( new GeoTest { Id = 1 , Shape = shape } ) ;
4649
47- var result = db . Select ( db . From < GeoTestTable > ( ) ) . First ( ) . Shape ;
50+ var result = db . SingleById < GeoTest > ( 1 ) . Shape ;
4851
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 " ) ;
5053
51- Assert . AreEqual ( ( double ) result . STLength ( ) , lengths . First ( ) ) ;
54+ Assert . AreEqual ( ( double ) result . STLength ( ) , lengths . First ( ) ) ;
5255
5356 Assert . AreEqual ( shape . STStartPoint ( ) . STX , result . STStartPoint ( ) . STX ) ;
5457 Assert . AreEqual ( shape . STStartPoint ( ) . STY , result . STStartPoint ( ) . STY ) ;
5558
5659 Assert . AreEqual ( shape . STEndPoint ( ) . STX , result . STEndPoint ( ) . STX ) ;
5760 Assert . AreEqual ( shape . STEndPoint ( ) . STY , result . STEndPoint ( ) . STY ) ;
5861
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 ( ) ;
6089 }
6190 }
6291 }
6392
64- public class GeoTestTable
93+ public class GeoTest
6594 {
66- [ AutoIncrement ]
6795 public long Id { get ; set ; }
6896
6997 public SqlGeography Location { get ; set ; }
0 commit comments