File tree Expand file tree Collapse file tree 5 files changed +86
-2
lines changed
NHSpecificTest/EntityWithDatetime2 Expand file tree Collapse file tree 5 files changed +86
-2
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Linq ;
3
+ using NHibernate . Linq ;
4
+ using NUnit . Framework ;
5
+
6
+ namespace NHibernate . Test . NHSpecificTest . EntityWithDatetime2
7
+ {
8
+ [ TestFixture ]
9
+ public class Fixture : BugTestCase
10
+ {
11
+ protected override void OnTearDown ( )
12
+ {
13
+ using ( var s = OpenSession ( ) )
14
+ using ( var tx = s . BeginTransaction ( ) )
15
+ {
16
+ s . CreateSQLQuery ( "delete from LogEntry" ) . ExecuteUpdate ( ) ;
17
+ tx . Commit ( ) ;
18
+ }
19
+ }
20
+
21
+ [ Test ]
22
+ public void ShouldBePossibleToReadMillisecondsFromDatetime2ViaCreateSQLQuery ( )
23
+ {
24
+ var now = DateTime . UtcNow ;
25
+
26
+ using ( var session = OpenSession ( ) )
27
+ using ( var transaction = session . BeginTransaction ( ) )
28
+ {
29
+ var entry = new LogEntry { Text = "Test" , CreatedAt = now } ;
30
+ session . Save ( entry ) ;
31
+
32
+ session . Flush ( ) ;
33
+ transaction . Commit ( ) ;
34
+ }
35
+
36
+ using ( var session = OpenSession ( ) )
37
+ {
38
+ var datetimeViaQuery = session
39
+ . Query < LogEntry > ( )
40
+ . Select ( x => x . CreatedAt )
41
+ . Single ( ) ;
42
+
43
+ Assert . That ( datetimeViaQuery . Millisecond , Is . EqualTo ( now . Millisecond ) ) ;
44
+
45
+ var datetimeViaCreateSqlQuery = session . CreateSQLQuery ( "SELECT CreatedAt FROM LogEntry" )
46
+ . List ( )
47
+ . Cast < DateTime > ( )
48
+ . Single ( ) ;
49
+
50
+ Assert . That ( datetimeViaCreateSqlQuery . Millisecond , Is . EqualTo ( now . Millisecond ) ) ;
51
+ }
52
+ }
53
+ }
54
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace NHibernate . Test . NHSpecificTest . EntityWithDatetime2
4
+ {
5
+ public class LogEntry
6
+ {
7
+ public virtual int Id { get ; set ; }
8
+ public virtual string Text { get ; set ; }
9
+ public virtual DateTime CreatedAt { get ; set ; }
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <hibernate-mapping xmlns =" urn:nhibernate-mapping-2.2"
3
+ assembly =" NHibernate.Test"
4
+ namespace =" NHibernate.Test.NHSpecificTest.EntityWithDatetime2" >
5
+
6
+ <class name =" LogEntry" >
7
+ <id name =" Id" type =" Int32" generator =" native" />
8
+ <property name =" Text" type =" string" />
9
+ <property name =" CreatedAt" type =" datetime2" />
10
+ </class >
11
+
12
+ </hibernate-mapping >
Original file line number Diff line number Diff line change 1363
1363
<Compile Include =" NHSpecificTest\NH3800\Fixture.cs" />
1364
1364
<Compile Include =" NHSpecificTest\NH3757\Fixture.cs" />
1365
1365
<Compile Include =" NHSpecificTest\NH3757\Money.cs" />
1366
+ <Compile Include =" NHSpecificTest\EntityWithDatetime2\Fixture.cs" />
1367
+ <Compile Include =" NHSpecificTest\EntityWithDatetime2\LogEntry.cs" />
1366
1368
<Compile Include =" NHSpecificTest\Properties\CompositePropertyRefTest.cs" />
1367
1369
<Compile Include =" NHSpecificTest\Properties\DynamicEntityTest.cs" />
1368
1370
<Compile Include =" NHSpecificTest\Properties\Model.cs" />
3247
3249
<EmbeddedResource Include =" NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
3248
3250
</ItemGroup >
3249
3251
<ItemGroup >
3252
+ <EmbeddedResource Include =" NHSpecificTest\EntityWithDatetime2\Mappings.hbm.xml" />
3250
3253
<EmbeddedResource Include =" Insertordering\FamilyModel\Mappings.hbm.xml" />
3251
3254
<EmbeddedResource Include =" Insertordering\AnimalModel\Mappings.hbm.xml" />
3252
3255
<EmbeddedResource Include =" NHSpecificTest\NH3247\Mappings.hbm.xml" />
Original file line number Diff line number Diff line change @@ -549,8 +549,12 @@ public string GetColumnName(int position)
549
549
/// <returns>The Hibernate type.</returns>
550
550
public IType GetHibernateType ( int columnPos )
551
551
{
552
- return TypeFactory . Basic ( resultSet . GetFieldType ( columnPos ) . Name ) ;
553
- }
552
+ var type = TypeFactory . Basic ( resultSet . GetDataTypeName ( columnPos ) ) ;
553
+ if ( type == null )
554
+ return TypeFactory . Basic ( resultSet . GetFieldType ( columnPos ) . Name ) ;
555
+
556
+ return type ;
557
+ }
554
558
}
555
559
}
556
560
}
You can’t perform that action at this time.
0 commit comments