【问题标题】:Issue using NHibernate's DateDiff使用 NHibernate 的 DateDiff 的问题
【发布时间】:2013-01-18 14:06:04
【问题描述】:

我在代码中使用以下 HQL

string sPastDueForCustomer = @"select 
    inv.fInvoiceDate as fInvoiceDate,
    cust.fName as fCustomerName,
    inv.fInvoiceNumberDisplay as fInvoiceNumberDisplay,
    inv.fBalance as fBalance,   
    inv.fDueDate as fDueDate,
    datediff(day, :GenerateDate, inv.fDueDate) as fDaysPastDue
    FROM tARInvoice as inv INNER JOIN inv.Customer as cust
    Where inv.fDueDate < :GenerateDate - " 
    + 
    ARApplicationSetup[0].fGracePeriod 
    + 
    @"  
    And inv.fInvoiceType= 'Manual'  
    And inv.fCustomerID = :CustomerID  
    And inv.fBalance > 0  
    And inv.fIsPosted = 1  
    And inv.fIsVoided = 0";                

    //get the result of query and return the object of PaymentInvoiceDetails
    IList<tARInvoice> PastDueForCustomer = 
        Session.CreateQuery(sPastDueForCustomer)
               .SetGuid("CustomerID", CustomerId)
               .SetDateTime("GenerateDate", GenerateDate)
               .SetResultTransformer(Transformers.AliasToBean<tARInvoice())
               .List<tARInvoice>();

当我运行它时,我收到以下错误:

No data type for node: 
MethodNode (datediff(exprList day ? (tarinvoice0_.fDueDate tarinvoice0_.fARInvoiceID fDueDate)))
[select
    inv.fInvoiceDate as fInvoiceDate,
    cust.fName as fCustomerName,
    inv.fInvoiceNumberDisplay as fInvoiceNumberDisplay,
    inv.fBalance as fBalance,   
    inv.fDueDate as fDueDate
    ,datediff(day, :GenerateDate,inv.fDueDate) as fDaysPastDue 
    FROM tARInvoice as inv INNER JOIN inv.Customer as cust
    Where inv.fDueDate < :GenerateDate - 15  
    And inv.fInvoiceType= 'Manual'  
    And inv.fCustomerID = :CustomerID  
    And inv.fBalance > 0  
    And inv.fIsPosted = 1  
    And inv.fIsVoided = 0]

fDaysPastDue 的类型是int

【问题讨论】:

  • 请重新格式化您的问题..

标签: c# nhibernate hql


【解决方案1】:

在这里,

WHERE inv.fDueDate < :GenerateDate - " + ARApplicationSetup[0].fGracePeriod + @" ... 

您从DateTime 中减去int,变成了这个,

WHERE inv.fDueDate < :GenerateDate - 15

由于操作涉及不同类型而引发错误。

确保您使用来自GenerateDate 变量的正确类型,并在您的查询中正确设置它,

Session.CreateQuery(sPastDueForCustomer)
       .SetGuid("CustomerID", CustomerId)
       .SetInt32("GenerateDate", GenerateDate.Days) 
       // instead of: ".SetDateTime(GenerateDate)"
       ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多