5

के लिए मानदंड क्वेरी कैसे बनाएं I इस समकक्ष एसक्यूएल क्वेरी के लिए आईसीआरटीरिया क्वेरी बना रहा हूं।दिए गए एसक्यूएल क्वेरी

SELECT fCustomerID, 
     ISNULL(
       (SELECT SUM(payinv.fAmount) AS Expr1 
       FROM dbo.tARPayment AS pay 
       INNER JOIN dbo.tARPaymentInvoice AS payinv ON pay.fPaymentID = payinv.fPaymentID 
       INNER JOIN dbo.tARInvoice AS inv ON payinv.fInvoiceID = inv.fARInvoiceID 
       WHERE (pay.fIsPosted = CASE pay.fPaymentType WHEN 'CM' THEN 0 WHEN 'EPD' THEN 0 ELSE 1 END) 
        AND (inv.fCustomerID <> dbo.tARCustomer.fCustomerID) 
        AND (pay.fCustomerID = dbo.tARCustomer.fCustomerID)), 0) 
FROM dbo.tARCustomer 
GROUP BY fCustomerID 

लेकिन मुझे वैसे भी नहीं मिल रहा है कि मैं बराबर निबर्नेट आईसीआरटीरिया क्वेरी कैसे उत्पन्न कर सकता हूं।

यह भुगतान वर्ग

public partial class tARPayment 
{ 
    #region Constructor 

    /// <summary> 
    /// Initializes a new instance of the <see cref="tARPayment"/> class. 
    /// </summary> 
    public tARPayment() 
    { 
    } 

    /// <summary> 
    /// Initializes a new instance of the <see cref="tARPayment"/> class. 
    /// </summary> 
    /// <param name="fPaymentID">The fPaymentID of guid type.</param> 
    public tARPayment(System.Guid fPaymentID) 
    { 
     this.ID = fPaymentID; 
    } 
    #endregion 

    #region Properties 

    /// <summary> 
    /// Gets or sets payment id. 
    /// </summary> 
    public virtual System.Guid fPaymentID { get; set; } 

    /// <summary> 
    /// Gets or sets fCustomerID. 
    /// </summary> 
    public virtual System.Guid fCustomerID { get; set; } 

    /// <summary> 
    /// Gets or sets check number. 
    /// </summary> 
    public virtual string fCheckNumber { get; set; } 

    /// <summary> 
    /// Gets or sets amount. 
    /// </summary> 
    public virtual decimal fAmount { get; set; }  

    /// <summary> 
    /// Gets or sets customer detail. 
    /// </summary> 
    public virtual tARCustomer Customer { get; set; } 

    public virtual IList<tARPaymentInvoice> PaymentInvoices { get; set; }   

    #endregion 

    #region Methods 
    /// <summary> 
    /// partial class for payment. 
    /// </summary> 
    /// <returns>The method get code.</returns> 
    public override int GetHashCode() 
    { 
     return ID.GetHashCode(); 
    } 
    #endregion 
} 

यह एक चालान वर्ग

public partial class tARInvoice 
{ 
    #region Constructor 
    /// <summary> 
    /// Initializes a new instance of the <see cref="tARInvoice"/> class. 
    /// </summary> 
    public tARInvoice() 
    { 
    } 

    /// <summary> 
    /// Initializes a new instance of the <see cref="tARInvoice"/> class. 
    /// </summary> 
    /// <param name="fARInvoiceID">The fARInvoiceID.</param> 
    public tARInvoice(System.Guid fARInvoiceID) 
    { 
     this.ID = fARInvoiceID; 
    } 

    #endregion 

    #region Properties 
    /// <summary> 
    /// Gets or sets fARInvoiceID. 
    /// </summary> 
    public virtual Guid fARInvoiceID { get; set; } 

    /// <summary> 
    /// Gets or sets fCustomerID. 
    /// </summary> 
    public virtual Guid fCustomerID { get; set; } 


    /// <summary> 
    /// Gets or sets Delivery Method. 
    /// </summary> 
    public virtual string fDeliveryMethod { get; set; } 

    /// <summary> 
    /// Gets or sets Invoice Number. 
    /// </summary> 
    public virtual int? fARInvoiceNumber { get; set; } 



    public virtual tARCustomer Customer { get; set; } 

    public virtual IList<tARPaymentInvoice> PaymentInvoices { get; set; }   

    #endregion 

    #region Methods 
    /// <summary> 
    /// retrieve Hash Code. 
    /// </summary> 
    /// <returns>The method get code.</returns> 
    public override int GetHashCode() 
    { 
     return ID.GetHashCode(); 
    } 
    #endregion 
} 

यह एक चालान का भुगतान करने वर्ग है है।

public partial class tARPaymentInvoice 
{ 
    #region Constructor 
    /// <summary> 
    /// Initializes a new instance of the <see cref="tARPaymentInvoice"/> class. 
    /// </summary> 
    public tARPaymentInvoice() 
    { 
    } 

    /// <summary> 
    /// Initializes a new instance of the <see cref="tARPaymentInvoice"/> class. 
    /// </summary> 
    /// <param name="fPaymentInvoiceID">The Invoice ID.</param> 
    public tARPaymentInvoice(System.Guid fPaymentInvoiceID) 
    { 
     this.ID = fPaymentInvoiceID; 
    } 
    #endregion 

    #region Properties 
    /// <summary> 
    /// Gets or sets fPaymentInvoiceID. 
    /// </summary> 
    public virtual System.Guid fPaymentInvoiceID { get; set; } 

    /// <summary> 
    /// Gets or sets fPaymentID. 
    /// </summary> 
    public virtual System.Guid fPaymentID { get; set; } 

    /// <summary> 
    /// Gets or sets fInvoiceID. 
    /// </summary> 
    public virtual System.Guid fInvoiceID { get; set; }   


    /// <summary> 
    /// Gets or sets tARPayment. 
    /// </summary> 
    public virtual tARPayment Payment { get; set; } 

    /// <summary> 
    /// Gets or sets tARInvoice. 
    /// </summary> 
    public virtual tARInvoice Invoice { get; set; } 

    #endregion 

    #region Methods 
    /// <summary> 
    /// get hash codes. 
    /// </summary>   
    /// <returns>The hash code.</returns> 
    public override int GetHashCode() 
    { 
     return ID.GetHashCode(); 
    } 
    #endregion 
} 
+0

मैंने नमूना कक्षाओं को अद्यतन किया था। – Awadhendra

+0

क्या आपने कोई प्रगति की है? क्या एचक्यूएल या LINQ के विपरीत विशेष रूप से मानदंड एपीआई का उपयोग करना महत्वपूर्ण है? –

+0

नहीं, मुझे कोई सफलता नहीं मिल रही है। हम एचक्यूएल का उपयोग कर सकते हैं लेकिन मुझे यकीन नहीं है कि एचक्यूएल सभी डेटाबेस के लिए समान है या कौन सा बेहतर है – Awadhendra

उत्तर

0

बल्कि LINQ या HQL करने के लिए ऊपर जिज्ञासा को परिवर्तित करने के बजाय, मैं एक दृश्य में क्वेरी करने होंगे और फिर उस दृश्य क्वेरी करने के लिए NHibernate का उपयोग कर की सिफारिश करेंगे।

एसक्यूएल

CREATE VIEW vCustomerAmount AS 
SELECT fCustomerID, 
     ISNULL(
       (SELECT SUM(payinv.fAmount) AS Expr1 
       FROM dbo.tARPayment AS pay 
       INNER JOIN dbo.tARPaymentInvoice AS payinv ON pay.fPaymentID = payinv.fPaymentID 
       INNER JOIN dbo.tARInvoice AS inv ON payinv.fInvoiceID = inv.fARInvoiceID 
       WHERE (pay.fIsPosted = CASE pay.fPaymentType WHEN 'CM' THEN 0 WHEN 'EPD' THEN 0 ELSE 1 END) 
        AND (inv.fCustomerID <> dbo.tARCustomer.fCustomerID) 
        AND (pay.fCustomerID = dbo.tARCustomer.fCustomerID)), 0) [Amount] 
FROM dbo.tARCustomer 
GROUP BY fCustomerID 

सी # डीटीओ

public class CustomerAmount 
{ 
    public int fCustomerID { get; set; } 
    public decimal Amount { get; set; } 
} 

क्वेरी

List<CustomerAmount> customerAmounts = session.Query<CustomerAmount>().ToList(); 
0
नहीं

यकीन nHibernate के बारे में है, लेकिन करना क्या यह पुनः लिखा गया प्रश्न एक ही उत्तर प्राप्त करने में मदद करता है और ऐसा कुछ है जिसे आप आसानी से चला सकते हैं?

SELECT T.fCustomerID, 
     coalesce(SUM(payinv.fAmount), 0) as SumAmt 
    FROM 
     dbo.tARCustomer T 
     JOIN dbo.tARPayment AS pay 
      ON T.fCustomerID = pay.fCustomerID 
      AND pay.fIsPosted = CASE pay.fPaymentType 
           WHEN 'CM' THEN 0 
           WHEN 'EPD' THEN 0 
           ELSE 1 END 
      JOIN dbo.tARPaymentInvoice AS payinv 
       ON pay.fPaymentID = payinv.fPaymentID 
       INNER JOIN dbo.tARInvoice AS inv 
        ON payinv.fInvoiceID = inv.fARInvoiceID 
       AND inv.fCustomerID <> T.fCustomerID 
    GROUP BY 
     T.fCustomerID