Reputation: 1432
I'm trying to map class to called a stored procedure with NHibernate
I have a class:
public class OrderDetails
{
public virtual int OrderNumber { get; set; }
public virtual DateTime OrderDate { get; set; }
public virtual int ProductCode { get; set; }
public virtual string ProductName { get; set; }
public virtual int Quantity { get; set; }
public virtual decimal Price { get; set; }
}
and mapping for this class:
<class name="OrderDetails" >
<id name="OrderNumber" column="ID"/>
<property name="OrderNumber" column="ID"/>
<property name="OrderDate" column="OrderDate"/>
<property name="ProductCode" column="productCode"/>
<property name="ProductName" column="Name"/>
<property name="Quantity" column="Quantity"/>
<property name="Price" column="UnitPrice"/>
<loader query-ref="GetOrdersByDate" />
</class>
<sql-query name="GetOrdersByDate" callable="true">
exec [dbo].[sp_OrdersByDate] :DateFrom, :DateTo
</sql-query>
When I call this query I get an exception
Could not find a setter for property 'ID' in class 'OrderDetails'
How can I map this columns to class properties?
Upvotes: 1
Views: 365
Reputation: 123901
Disclaimer: Ready to delete this ... if still no help...
This is my SP (MS SQL)
CREATE PROCEDURE [dbo].[sp_OrdersByDate]
@DateFrom DateTime,
@DateTo DateTime
AS
BEGIN
SET NOCOUNT ON;
SELECT 1 as ID
, '2011-01-01' AS OrderDate
, 123 AS productCode
, 'XYZ' AS Name
, 1 AS Quantity
, 100 AS UnitPrice
END
GO
This is the mapping (tested)
<class name="OrderDetails" >
<id name="OrderNumber" column="ID" />
<property name="OrderDate" column="OrderDate"/>
<property name="ProductCode" column="productCode"/>
<property name="ProductName" column="Name"/>
<property name="Quantity" column="Quantity"/>
<property name="Price" column="UnitPrice"/>
<loader query-ref="GetOrdersByDate" />
</class>
<sql-query name="GetOrdersByDate" callable="true">
<return class="OrderDetails"></return>
exec [dbo].[sp_OrdersByDate] :DateFrom, :DateTo
</sql-query>
And this is the query (working)
var query = session.GetNamedQuery("GetOrdersByDate");
query.SetParameter("DateFrom", new DateTime(2013, 10, 26));
query.SetParameter("DateTo", new DateTime(2020, 12, 26));
var list = query.List<OrderDetails>();
Upvotes: 1