NHibernate要查询的地图类属性

时间:2017-07-26 16:58:37

标签: asp.net-mvc nhibernate nhibernate-mapping

我试图将类映射到使用NHibernate调用存储过程

我有一个班级:

Dim rng As Range
Set rng = ws1.Range("R2:R6000")

Dim MaxValue as Double
MaxValue = Application.WorksheetFunction.Max(rng,6) 'this will force 6 or >

Dim dCounter as Double

Do 

    dCounter = dCounter + .1

    'adjust this fill range to whatever you need        
    Range("A" & Rows.Count).End(xlup).Offset(1).Value = dCounter

Loop Until dCounter = MaxValue

和此类的映射:

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; }
}

当我调用此查询时,我得到一个异常

  

无法找到属性' ID'在课堂' OrderDetails'

如何将此列映射到类属性?

1 个答案:

答案 0 :(得分:1)

免责声明:准备删除此内容...如果仍然没有帮助...

这是我的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

这是映射(已测试)

<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>

这是查询(工作)

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>();