2012-06-21 98 views
0

我正在轉換遺留系統的數據層使用NHibernate。舊的數據庫加載了我想要映射的存儲過程。我被事物的命名所撕毀。這些特效不返回簡單的實體,它們返回一團糟。一個例子是這樣的:NHibernate存儲過程命名

USE [MYDB] 
GO 
/****** Object: StoredProcedure [dbo].[GetInvoiceRenewals] Script Date: 06/21/2012 10:24:05 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
-- ============================================= 
-- Author:  <Author,,Name> 
-- Create date: <Create Date,,> 
-- Description: <Description,,> 
-- ============================================= 
ALTER PROCEDURE [dbo].[GetInvoiceRenewals] 
@ClientId int, 
@UserId int 
AS 
BEGIN 
-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with SELECT statements. 
SET NOCOUNT ON; 


IF (@ClientId IN (SELECT ClientId FROM dbo.UserClientIds(@UserId))) 
BEGIN 

    SELECT I.InvoiceId, I.ClientId, I.InvoiceTypeId, I.InvoiceNumber, I.QuoteNumber, I.PONumber, 
     I.TotalListPrice, I.EstimatedFee, I.ActualFee, I.DateCreated, u.firstname + ' ' + u.lastname as 'UserCreated',i.billingAddressID,i.shippingAddressID, 
     I.ActualClientPrice, 
     (select InvoiceStatus from InvoiceStatus where invoiceStatusID = (Select Case When Not Exists (Select * from InvoiceStatusHistory where InvoiceId=I.InvoiceID) Then 1 
Else (Select top 1 InvoiceStatusID from InvoiceStatusHistory where InvoiceId=I.InvoiceID Order By ActionDate Desc) End)) as Status 
    FROM Invoice I, [user] u 
    WHERE I.ClientId = @ClientId AND I.IsActive = 1 AND I.InvoiceTypeId = 3 and u.userID = i.userCreated 

END 
END 


--Select Case When Not Exists (Select * from InvoiceStatusHistory where InvoiceId=I.InvoiceID) Then 1 
-- Else (Select InvoiceStatusID from InvoiceStatusHistory where InvoiceId=I.InvoiceID) End 
-- 
--InvoiceStatusID is NULL then 1 else InvoiceStatusID END from InvoiceStatusHistory 
--       where InvoiceId=1860 Order By ActionDate Desc 

現在的圖片數以百計。我顯然會編寫一個腳本來將所有這些生成到HBM文件中,並創建實體。我在尋找的是這些proc實體的良好命名結構?有什麼想法嗎?

回答

1

我不認爲NHibernate真的很適合這個。如果你將它轉換爲NHibernate,那麼你應該真的將你的實體映射到表(粗略),而不是存儲過程。

此外,在這個例子中,你有存儲過程中的邏輯,它將更好地用代碼表示,這將需要將你的實體映射到表並從這些實體中工作。

既然你想遷移到NHibernate,我會建議將你的實體映射到表,然後將應用程序逐步遷移到使用實體,並保持原樣使用存儲的特效(如果你願意,你可以隨時調用存儲proc使用session.CreateSQLQuery(「...」))

+0

我想要取消所有的存儲過程。我的方法是慢遷移,使用NHibernates CreateSQLQuery將整個數據層轉換爲NHibernate,包括舊的特效。一旦我將所有東西都運行起來,我就可以慢慢地開始在linq中獲取所有東西,並從存儲的特效庫中剔除業務邏輯。再次,我只是想要命名我將映射存儲過程的實體。 –