NHibernate存储过程命名

时间:2012-06-21 15:30:13

标签: nhibernate stored-procedures naming-conventions

我正在将遗留系统的数据层转换为使用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 个答案:

答案 0 :(得分:1)

我不认为NHibernate真的很适合这个。如果你将它转换为NHibernate,那么你应该将你的实体映射到表(粗略地),而不是存储过程。

同样在这个例子中,你的存储过程中有逻辑,imo,可以在代码中更好地表达,这需要将你的实体映射到表并从这些实体中工作。

由于您要迁移到NHibernate,我建议将您的实体映射到表,然后逐步将应用程序迁移到使用实体,并使用存储过程保留原样(如果需要,您可以随时调用存储过程)使用session.CreateSQLQuery(“...”))