0

Nhibernate で名前付きクエリを使用してプロシージャを呼び出すときに問題に直面しています。単純なプロシージャ/パラメータ化されたプロシージャを簡単に呼び出すことができますが、3 つの引数を受け入れるプロシージャがあります。最後はビットタイプです。

次の手順があります。

CREATE PROCEDURE [dbo].[ar_tARCustomer_ReadAccount_ForBalanceDetail]    

 @CustomerList varchar(max),    
 @AsOfDate  varchar(50),    
 @PostedOnly  bit    

AS    



SET NOCOUNT ON;    

Declare @ErrorNumber int    
Declare @SQL   varchar(max)    
Declare @PostedInvoice varchar(50)    
Declare @PostedPayment varchar(200)    

SET @PostedInvoice = ''    
SET @PostedPayment=  ''    
IF (@PostedOnly = 1)    
BEGIN    
 SET @PostedInvoice = ' And ari.fIsPosted = 1 '    
 SET @PostedPayment = ' And pay.fIsPosted =     
   CASE pay.fPaymentType    
     WHEN ''CM'' THEN 0    
     WHEN ''EPD'' THEN 0    
     ELSE 1    
   END'    
END    

Set @SQL =     
'    
select * from    
(    
 Select Distinct    
   co.fName as fTrxCompanyName, prop.fName as fTrxPropertyName, arc.fName as fTrxCustomerName,       
   cast(ari.fARInvoiceNumber  as varchar(10)) as fTrxNumber,    
   ari.fInvoiceDescription as fTrxDescription,    
   ari.fIsVoided as fTrxIsVoided,    
   CASE fInvoiceType    
     WHEN ''Credit Memo'' THEN fBalance    
     WHEN ''Early Payment Discount'' THEN fBalance    
     ELSE fAmount    
   END as fTrxAmount    
 From tARInvoice ari    
  Inner Join tARCustomer arc on arc.fCustomerID = ari.fCustomerID    
  LEFT OUTER JOIN tSCCompany co on co.fCompanyID = arc.fCompanyID    
  LEFT OUTER JOIN tSCProperty prop on prop.fPropertyID = arc.fPropertyID     
 Where ari.fCustomerID in (' + @CustomerList + ') and    
    ari.fInvoiceDate >= convert(datetime,'+ '''' + @AsOfDate + '''' + ') and    
    ari.fInvoiceType <> ''Recurring Template''' + @PostedInvoice + '    

 Union All    

 Select  Distinct    
   co.fName as fTrxCompanyName, prop.fName as fTrxPropertyName, cust.fName as fTrxCustomerName,         
   ''Payment'' as fTrxType,     
   null,         
   pay.fComments as fTrxDescription,    
   pay.fIsVoided as fTrxIsVoided,    
            pay.fAmount as fTrxAmount    
 From tARPayment pay    
  Left Outer Join tARPaymentInvoice payinv On pay.fPaymentID = payinv.fPaymentID    
  Left Outer Join tARInvoice inv On payinv.fInvoiceID = inv.fARInvoiceID    
  Left Outer Join tARCustomer cust on cust.fCustomerID = pay.fCustomerID    
  LEFT OUTER JOIN tSCCompany co on co.fCompanyID = cust.fCompanyID    
  LEFT OUTER JOIN tSCProperty prop on prop.fPropertyID = cust.fPropertyID      
 Where (inv.fCustomerID IN (' + @CustomerList +')    
  OR (pay.fCustomerID IN (' + @CustomerList +') AND (inv.fCustomerID NOT IN (' + @CustomerList +') OR inv.fCustomerID IS NULL))    
  OR ((pay.fCustomerID IS NULL OR pay.fCustomerID NOT IN (' + @CustomerList +')) AND inv.fCustomerID IN (' + @CustomerList +')))    
  and pay.fEffectiveDate >= convert(datetime,' + '''' + @AsOfDate + '''' + ')'        + @PostedPayment + '    

 Union All    

-- Get the voided payments only with the reversed payment amount and the voided description    
 Select  Distinct    
   co.fName as fTrxCompanyName, prop.fName as fTrxPropertyName, cust.fName as fTrxCustomerName,       
   ''Payment'' as fTrxType,     
   null,    
   pay.fVoidedDate as fTrxAddedDate,    
   pay.fUnappliedAmount as fTrxBalance,    
   cast(pay.fCheckNumber as varchar(10)) as fTrxNumber,    
   ''Voided Early Payment Discount #'' + cast(pay.fCheckNumber as varchar(10)) as fTrxDescription,    
   pay.fIsVoided as fTrxIsVoided,    
            (-1 * pay.fAmount) as fTrxAmount    
 From tARPayment pay    
  Left Outer Join tARPaymentInvoice payinv On pay.fPaymentID = payinv.fPaymentID    
  Left Outer Join tARInvoice inv On payinv.fInvoiceID = inv.fARInvoiceID    
  Left Outer Join tARCustomer cust on cust.fCustomerID = pay.fCustomerID    
  LEFT OUTER JOIN tSCCompany co on co.fCompanyID = cust.fCompanyID    
  LEFT OUTER JOIN tSCProperty prop on prop.fPropertyID = cust.fPropertyID      
 Where (inv.fCustomerID IN (' + @CustomerList +')    
  OR (pay.fCustomerID IN (' + @CustomerList +') AND (inv.fCustomerID NOT IN (' + @CustomerList +') OR inv.fCustomerID IS NULL))    
  OR ((pay.fCustomerID IS NULL OR pay.fCustomerID NOT IN (' + @CustomerList +')) AND inv.fCustomerID IN (' + @CustomerList +')))    
  and pay.fIsVoided = 1    
  and pay.fVoidedDate >= convert(datetime,' + '''' + @AsOfDate + '''' + ')'     
   + @PostedPayment + '    
) X    
Where fTrxAmount IS NOT NULL    
Order By fTrxCompanyName, fTrxPropertyName, fTrxAddedDate    
'    
Exec (@SQL)    
--print (@SQL)    

RETURN (@@Error) 

次のコードをhbmファイルに書きました。

<sql-query name="ar_tARCustomer_ReadAccount_ForBalanceDetail_New" callable="true">
    <!--<query-param name="CustomerList" type="VARCHAR(max)" />
    <query-param name="AsOfDate" type="string" />
    <query-param name="PostedOnly" type="bool" />-->
    <return class="tARCustomer">
      <return-property column="fTrxCompanyName" name="fTrxCompanyName" />
      <return-property column="fTrxPropertyName" name="fTrxPropertyName" />
      <return-property column="fTrxCustomerName" name="fTrxCustomerName" />
      <return-property column="fCustomerID" name="fTrxCustomerID" />
      <return-property column="fTrxSourceID" name="fTrxSourceID" />
      <return-property column="fInvoicePosted" name="fInvoicePosted" />
      <return-property column="fTrxDate" name="fTrxDate" />
      <return-property column="fPostedDate" name="fPostedDate" />
      <return-property column="fTrxType" name="fTrxType" />
      <return-property column="fTrxDueDate" name="fTrxDueDate" />
      <return-property column="fTrxAddedDate" name="fTrxAddedDate" />
      <return-property column="fTrxBalance" name="fTrxBalance" />
      <return-property column="fTrxDescription" name="fTrxDescription" />
      <return-property column="fTrxIsVoided" name="fTrxIsVoided" />
      <return-property column="fTrxAmount" name="fTrxAmount" />
    </return>

    exec ar_tARCustomer_ReadAccount_ForBalanceDetail_New
    @CustomerList=:CustomerList,
    @AsOfDate=:AsOfDate,
    @PostedOnly=:PostedOnly
  </sql-query>

そして、このプロシージャを呼び出すために、次のコードを書きました。

var Customerbalance = Session.GetNamedQuery("ar_tARCustomer_ReadAccount_ForBalanceDetail_New")
                                           .SetParameter("CustomerList", "'''bced443a-ce86-4675-bca6-ae5646ad9c2e'' , ''bced443a-ce86-4675-bca6-ae5646ad9c2e'''")
                                           .SetParameter("AsOfDate", "10/1/2012")
                                           .SetParameter("PostedOnly", PostedOnly)
                                           .SetResultTransformer(new AliasToBeanResultTransformer(typeof(tARCustomer))).List<tARCustomer>();

ここでは、NHibernate を使用してパラメーターをプロシージャーに渡すためのすべてのタイプの組み合わせを試しましたが、常にクラッシュしました。

4

1 に答える 1