1
1
using System ;
2
2
using System . Data . SqlClient ;
3
+ using System . Data . SqlTypes ;
3
4
using NUnit . Framework ;
4
5
using ServiceStack . DataAnnotations ;
5
6
using ServiceStack . OrmLite . SqlServer ;
@@ -23,8 +24,7 @@ public void datetime_tests__can_use_datetime2()
23
24
conn . CreateTable < Table_for_datetime2_tests > ( true ) ;
24
25
25
26
//normal insert
26
- conn . Insert ( test_object_ValidForDatetime2 ) ;
27
- var insertedId = ( int ) conn . LastInsertId ( ) ;
27
+ var insertedId = conn . Insert ( test_object_ValidForDatetime2 , selectIdentity : true ) ;
28
28
29
29
//read back, and verify precision
30
30
var fromDb = conn . SingleById < Table_for_datetime2_tests > ( insertedId ) ;
@@ -56,17 +56,16 @@ public void datetime_tests__check_default_behaviour()
56
56
conn . CreateTable < Table_for_datetime2_tests > ( true ) ;
57
57
58
58
//normal insert
59
- conn . Insert ( test_object_ValidForNormalDatetime ) ;
60
- var insertedId = conn . LastInsertId ( ) ;
59
+ var insertedId = conn . Insert ( test_object_ValidForNormalDatetime , selectIdentity : true ) ;
61
60
62
61
//insert works, but can't regular datetime's precision is not great enough.
63
62
var fromDb = conn . SingleById < Table_for_datetime2_tests > ( insertedId ) ;
64
63
Assert . AreNotEqual ( test_object_ValidForNormalDatetime . ToVerifyPrecision , fromDb . ToVerifyPrecision ) ;
65
64
66
- var thrown = Assert . Throws < SqlException > ( ( ) => {
65
+ var thrown = Assert . Throws < SqlTypeException > ( ( ) => {
67
66
conn . Insert ( test_object_ValidForDatetime2 ) ;
68
67
} ) ;
69
- Assert . That ( thrown . Message . Contains ( "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. ") ) ;
68
+ Assert . That ( thrown . Message . Contains ( "SqlDateTime overflow ") ) ;
70
69
71
70
72
71
//check InsertParam
0 commit comments