数据访问层的命名约定,尤其是在存储过程的情况下

时间:2022-02-28 16:58:08

Let's assume, we create a stored procedure that is supposed to retrieve customer details and that will be used in some sort of dashboard view. Since there are a couple of other stored procedures relevant for the dashboard as well, one might think about visually grouping the SPs by naming them accordingly:

让我们假设,我们创建一个存储过程,该过程应该检索客户详细信息,并将用于某种仪表板视图。由于还有一些与仪表板相关的其他存储过程,因此可以考虑通过相应地命名SP来对SP进行可视化分组:

  • DASH_GetCustomerDetails
  • DASH_...

Now if you create a standard DAL with .NET 2.0, you will most certainly add a strongly typed dataset and add some table adapters. By default the TA for the SP above would be named like DASH_GetCustomerDetailsTableAdapter with the datatable being DASH_GetCustomerDetailsDataTable and so on.

现在,如果您使用.NET 2.0创建标准DAL,您肯定会添加一个强类型数据集并添加一些表适配器。默认情况下,上面SP的TA将命名为DASH_GetCustomerDetailsTableAdapter,数据表为DASH_GetCustomerDetailsDataTable,依此类推。

Typically, you'll have some sort of business logic above them all. It might be called something like Customer with a protected property that instantiates the table adapter and a method GetDetails maybe for finally retrieving details. Or you even make that method a property itself calling it Details, so that the presentation layer can just say something like cust.Details or whatever.

通常,您将拥有某种业务逻辑。它可能被称为Customer,具有实例化表适配器的受保护属性,以及方法GetDetails可能最终检索详细信息。或者你甚至将该方法设置为一个属性本身,称之为Details,这样表示层就可以说像cust.Details或者其他什么。

However,... i am not satisfied with all that naming stuff. Could it be necessary to be able distinguishing between Stored Procedures working in the background, so that the naming should reflect that... is there any sort of best practice?

但是,...我对所有命名的东西都不满意。是否有必要能够区分在后台工作的存储过程,以便命名应该反映......是否有任何最佳实践?

1 个解决方案

#1


I would be tempted to remove the DASH from the front of the procedures. In general procedure names should reflect what the procedure does, not who is using it.

我很想从程序的前面删除DASH。通常,程序名称应反映程序的作用,而不是谁正在使用它。

Consider the extreme case:

考虑极端情况:

  • get_all_customers

vs

  • get_all_customers_for_dashboard
  • get_all_customers_for_invoice_background_job
  • get_all_customers_for_ad_hoc_report
  • ...

The fact that your stored procedures are used by a background part of your dashboard application is nothing to do with the procedures themselves, and naming them as such violates encapsulation.

您的存储过程由仪表板应用程序的后台部分使用这一事实与过程本身无关,并且将其命名为违反封装。

If you wrote another application that needed the same logical queries, would you write new procedures prefixed by APPNAME?

如果你编写了另一个需要相同逻辑查询的应用程序,你会编写以APPNAME为前缀的新程序吗?

#1


I would be tempted to remove the DASH from the front of the procedures. In general procedure names should reflect what the procedure does, not who is using it.

我很想从程序的前面删除DASH。通常,程序名称应反映程序的作用,而不是谁正在使用它。

Consider the extreme case:

考虑极端情况:

  • get_all_customers

vs

  • get_all_customers_for_dashboard
  • get_all_customers_for_invoice_background_job
  • get_all_customers_for_ad_hoc_report
  • ...

The fact that your stored procedures are used by a background part of your dashboard application is nothing to do with the procedures themselves, and naming them as such violates encapsulation.

您的存储过程由仪表板应用程序的后台部分使用这一事实与过程本身无关,并且将其命名为违反封装。

If you wrote another application that needed the same logical queries, would you write new procedures prefixed by APPNAME?

如果你编写了另一个需要相同逻辑查询的应用程序,你会编写以APPNAME为前缀的新程序吗?