Permalink
Browse files

Merge revision 2988

SVN: branches/1.2.x@2995
  • Loading branch information...
1 parent 8ae337e commit 1f9bc8dffe033243ad8d8b98bde14ad35c9412d9 Sergey Koshcheyev committed Sep 21, 2007
@@ -0,0 +1,34 @@
+#if NET_2_0
+using NUnit.Framework;
+
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH1119
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ public override string BugNumber
+ {
+ get { return "NH1119"; }
+ }
+
+ [Test]
+ public void SelectMinFromEmptyTable()
+ {
+ using (ISession s = OpenSession())
+ {
+ try
+ {
+ DateTime dt = s.CreateQuery("select max(tc.DateTimeProperty) from TestClass tc").UniqueResult<DateTime>();
+ string msg = "Calling UniqueResult<T> where T is a value type"
+ + " should throw InvalidCastException when the result"
+ + " is null";
+ Assert.Fail(msg);
+ }
+ catch (InvalidCastException) { }
+ }
+ }
+ }
+}
+#endif
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ namespace="NHibernate.Test.NHSpecificTest.NH1119"
+ assembly="NHibernate.Test">
+
+ <class name="TestClass" table="TestClassNH1119">
+ <id name="ID">
+ <generator class="native"/>
+ </id>
+ <property name="DateTimeProperty"/>
+ </class>
+
+</hibernate-mapping>
@@ -0,0 +1,21 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH1119
+{
+ public class TestClass
+ {
+ private int _ID;
+ public virtual int ID
+ {
+ get { return _ID; }
+ set { _ID = value; }
+ }
+
+ private DateTime _DateTimeProperty;
+ public virtual DateTime DateTimeProperty
+ {
+ get { return _DateTimeProperty; }
+ set { _DateTimeProperty = value; }
+ }
+ }
+}
@@ -221,6 +221,8 @@
<Compile Include="NHSpecificTest\BasicTimeFixture.cs" />
<Compile Include="NHSpecificTest\BugTestCase.cs" />
<Compile Include="NHSpecificTest\CollectionFixture.cs" />
+ <Compile Include="NHSpecificTest\NH1119\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1119\Model.cs" />
<Compile Include="NHSpecificTest\NH1018\Employee.cs" />
<Compile Include="NHSpecificTest\NH1018\Employer.cs" />
<Compile Include="NHSpecificTest\NH1018\NH1018Fixture.cs" />
@@ -912,6 +914,9 @@
<EmbeddedResource Include="NHSpecificTest\NH1018\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
+ <EmbeddedResource Include="NHSpecificTest\NH1119\Mappings.hbm.xml" />
+ </ItemGroup>
+ <ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@@ -929,4 +934,4 @@
copy "$(ProjectDir)\hibernate.cfg.xml" "hibernate.cfg.xml"
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent>
</PropertyGroup>
-</Project>
+</Project>
@@ -616,7 +616,15 @@ internal protected ISessionImplementor Session
#if NET_2_0
public T UniqueResult<T>()
{
- return (T) UniqueResult();
+ object result = UniqueResult();
+ if (result == null && typeof(T).IsValueType)
+ {
+ throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
+ }
+ else
+ {
+ return (T)UniqueResult();
+ }
}
#endif
@@ -767,4 +775,4 @@ public override string ToString()
return queryString;
}
}
-}
+}
@@ -122,7 +122,15 @@ public IList<T> List<T>()
public T UniqueResult<T>()
{
- return (T) UniqueResult();
+ object result = UniqueResult();
+ if (result == null && typeof(T).IsValueType)
+ {
+ throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
+ }
+ else
+ {
+ return (T)UniqueResult();
+ }
}
#endif

0 comments on commit 1f9bc8d

Please sign in to comment.