Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support for Single in LINQ expressions with Sum/Max/etc (NH-3031)

Added a property to the Northwind Product entity, called ShippingWeight, of
type Single (float in C#). Can be used for further tests with this type.
  • Loading branch information...
commit d88968bbd7dffec2e3f48127f077761f45e1de24 1 parent fd77b18
@julian-maughan julian-maughan authored
View
203 src/NHibernate.DomainModel/Northwind/Entities/Product.cs
@@ -3,102 +3,109 @@
namespace NHibernate.DomainModel.Northwind.Entities
{
- public class Thing
- {
- public int ProductId { get; set; }
- public decimal? UnitPrice { get; set; }
- public decimal? Other { get; set; }
-
- public Thing(int productId, decimal? unitPrice, decimal? other)
- {
- ProductId = productId;
- UnitPrice = unitPrice;
- Other = other;
- }
- }
-
- public class Product
- {
- private readonly IList<OrderLine> _orderLines;
- private ProductCategory _category;
- private bool _discontinued;
- private string _quantityPerUnit;
- private int _reorderLevel;
- private Supplier _supplier;
- private decimal? _unitPrice;
- private int _unitsInStock;
- private int _unitsOnOrder;
- private int _productId;
- private string _name;
-
- public Product()
- {
- _orderLines = new List<OrderLine>();
- }
-
- public virtual int ProductId
- {
- get { return _productId; }
- set { _productId = value; }
- }
-
- public virtual string Name
- {
- get { return _name; }
- set { _name = value; }
- }
-
- public virtual Supplier Supplier
- {
- get { return _supplier; }
- set { _supplier = value; }
- }
-
- public virtual ProductCategory Category
- {
- get { return _category; }
- set { _category = value; }
- }
-
- public virtual string QuantityPerUnit
- {
- get { return _quantityPerUnit; }
- set { _quantityPerUnit = value; }
- }
-
- public virtual decimal? UnitPrice
- {
- get { return _unitPrice; }
- set { _unitPrice = value; }
- }
-
- public virtual int UnitsInStock
- {
- get { return _unitsInStock; }
- set { _unitsInStock = value; }
- }
-
- public virtual int UnitsOnOrder
- {
- get { return _unitsOnOrder; }
- set { _unitsOnOrder = value; }
- }
-
- public virtual int ReorderLevel
- {
- get { return _reorderLevel; }
- set { _reorderLevel = value; }
- }
-
- public virtual bool Discontinued
- {
- get { return _discontinued; }
- set { _discontinued = value; }
- }
-
- public virtual ReadOnlyCollection<OrderLine> OrderLines
- {
- get { return new ReadOnlyCollection<OrderLine>(_orderLines); }
- }
- }
+ public class Thing
+ {
+ public int ProductId { get; set; }
+ public decimal? UnitPrice { get; set; }
+ public decimal? Other { get; set; }
+
+ public Thing(int productId, decimal? unitPrice, decimal? other)
+ {
+ ProductId = productId;
+ UnitPrice = unitPrice;
+ Other = other;
+ }
+ }
+
+ public class Product
+ {
+ private readonly IList<OrderLine> _orderLines;
+ private ProductCategory _category;
+ private bool _discontinued;
+ private string _quantityPerUnit;
+ private int _reorderLevel;
+ private Supplier _supplier;
+ private decimal? _unitPrice;
+ private int _unitsInStock;
+ private int _unitsOnOrder;
+ private int _productId;
+ private string _name;
+ private float _shippingWeight;
+
+ public Product()
+ {
+ _orderLines = new List<OrderLine>();
+ }
+
+ public virtual int ProductId
+ {
+ get { return _productId; }
+ set { _productId = value; }
+ }
+
+ public virtual string Name
+ {
+ get { return _name; }
+ set { _name = value; }
+ }
+
+ public virtual Supplier Supplier
+ {
+ get { return _supplier; }
+ set { _supplier = value; }
+ }
+
+ public virtual ProductCategory Category
+ {
+ get { return _category; }
+ set { _category = value; }
+ }
+
+ public virtual string QuantityPerUnit
+ {
+ get { return _quantityPerUnit; }
+ set { _quantityPerUnit = value; }
+ }
+
+ public virtual decimal? UnitPrice
+ {
+ get { return _unitPrice; }
+ set { _unitPrice = value; }
+ }
+
+ public virtual int UnitsInStock
+ {
+ get { return _unitsInStock; }
+ set { _unitsInStock = value; }
+ }
+
+ public virtual int UnitsOnOrder
+ {
+ get { return _unitsOnOrder; }
+ set { _unitsOnOrder = value; }
+ }
+
+ public virtual int ReorderLevel
+ {
+ get { return _reorderLevel; }
+ set { _reorderLevel = value; }
+ }
+
+ public virtual bool Discontinued
+ {
+ get { return _discontinued; }
+ set { _discontinued = value; }
+ }
+
+ public virtual float ShippingWeight
+ {
+ get { return _shippingWeight; }
+ set { _shippingWeight = value; }
+ }
+
+ public virtual ReadOnlyCollection<OrderLine> OrderLines
+ {
+ get { return new ReadOnlyCollection<OrderLine>(_orderLines); }
+ }
+ }
}
View
49 src/NHibernate.DomainModel/Northwind/Mappings/Product.hbm.xml
@@ -1,48 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
-<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
- namespace="NHibernate.DomainModel.Northwind.Entities" assembly="NHibernate.DomainModel">
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate.DomainModel.Northwind.Entities" assembly="NHibernate.DomainModel">
+
+ <import class="NHibernate.DomainModel.Northwind.Entities.Thing, NHibernate.DomainModel" />
- <import class="NHibernate.DomainModel.Northwind.Entities.Thing, NHibernate.DomainModel"/>
-
<class name="Product" table="Products">
- <id name="ProductId" column="ProductId" type="int" unsaved-value="-1"
- access="field.camelcase-underscore">
+
+ <id name="ProductId" column="ProductId" type="int" unsaved-value="-1" access="field.camelcase-underscore">
<generator class="assigned" />
</id>
- <property name="Name" column="ProductName" type="string" length="40"
- not-null="true" access="field.camelcase-underscore"/>
+ <property name="Name" column="ProductName" type="string" length="40" not-null="true" access="field.camelcase-underscore" />
+
+ <many-to-one name="Supplier" class="Supplier" column="SupplierId" access="field.camelcase-underscore" fetch="select" />
- <many-to-one name="Supplier" class="Supplier" column="SupplierId"
- access="field.camelcase-underscore" fetch="select"/>
+ <many-to-one name="Category" class="ProductCategory" column="CategoryId" access="field.camelcase-underscore" />
- <many-to-one name="Category" class="ProductCategory" column="CategoryId"
- access="field.camelcase-underscore" />
+ <property name="QuantityPerUnit" column="QuantityPerUnit" type="string" length="20" access="field.camelcase-underscore" />
- <property name="QuantityPerUnit" column="QuantityPerUnit" type="string" length="20"
- access="field.camelcase-underscore"/>
+ <property name="UnitPrice" column="UnitPrice" type="Decimal" access="field.camelcase-underscore" />
- <property name="UnitPrice" column="UnitPrice" type="Decimal"
- access="field.camelcase-underscore"/>
+ <property name="UnitsInStock" column="UnitsInStock" type="int" access="field.camelcase-underscore" />
- <property name="UnitsInStock" column="UnitsInStock" type="int"
- access="field.camelcase-underscore"/>
+ <property name="UnitsOnOrder" column="UnitsOnOrder" type="int" access="field.camelcase-underscore" />
- <property name="UnitsOnOrder" column="UnitsOnOrder" type="int"
- access="field.camelcase-underscore"/>
+ <property name="ReorderLevel" column="ReorderLevel" type="int" access="field.camelcase-underscore" />
- <property name="ReorderLevel" column="ReorderLevel" type="int"
- access="field.camelcase-underscore"/>
+ <property name="Discontinued" column="Discontinued" type="boolean" not-null="true" access="field.camelcase-underscore" />
- <property name="Discontinued" column="Discontinued" type="boolean"
- not-null="true" access="field.camelcase-underscore"/>
+ <property name="ShippingWeight" column="ShippingWeight" type="float" access="field.camelcase-underscore" />
- <bag name="OrderLines" lazy="true" access="field.camelcase-underscore"
- cascade="none">
- <key column="ProductId"/>
- <one-to-many class="OrderLine"/>
+ <bag name="OrderLines" lazy="true" access="field.camelcase-underscore" cascade="none">
+ <key column="ProductId" />
+ <one-to-many class="OrderLine" />
</bag>
</class>
-
+
</hibernate-mapping>
View
BIN  src/NHibernate.Test/DbScripts/MsSql2008DialectLinqReadonlyCreateScript.sql
Binary file not shown
View
BIN  src/NHibernate.Test/DbScripts/PostgreSQL82DialectLinqReadonlyCreateScript.sql
Binary file not shown
View
14 src/NHibernate.Test/Linq/ByMethod/SumTests.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Linq;
using NUnit.Framework;
namespace NHibernate.Test.Linq.ByMethod
@@ -43,5 +40,12 @@ public void SumNullableDecimal()
decimal? total = db.Orders.Sum(ol => ol.Freight);
Assert.Greater(total, 0);
}
+
+ [Test]
+ public void SumSingle()
+ {
+ float total = db.Products.Sum(p => p.ShippingWeight);
+ Assert.Greater(total, 0);
+ }
}
-}
+}
View
3  src/NHibernate/Hql/Ast/HqlTreeNode.cs
@@ -202,6 +202,9 @@ internal HqlIdent(IASTFactory factory, System.Type type)
case TypeCode.Decimal:
SetText("decimal");
break;
+ case TypeCode.Single:
+ SetText("single");
+ break;
case TypeCode.DateTime:
SetText("datetime");
break;
Please sign in to comment.
Something went wrong with that request. Please try again.