访问多个表的模型的命名模式

发布于 2024-11-27 23:29:56 字数 57 浏览 0 评论 0原文

我所知道的是,我们用表名来命名模型。 但是访问多个表的模型又如何呢? 它们的命名标准应该是什么?

What I know is that, We name model having table name.
But what about the model which access multiple table.
What should be the naming standard for them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

豆芽 2024-12-04 23:29:56

假设您的意思是在 MVC 模式的上下文中,模型是面向外的,由控制器进行操作并由视图进行消费。应该选择模型类的名称来帮助视图和控制器的作者。我不同意模型的实现细节的名称(数据库表)必然是模型类名称的正确基础。

举一个简单的例子:假设我们有一个 CUSTOMER 表。然后我们创建一个 Customer 类,一切都非常好,我们完全理解它。现在假设出于性能原因(在这个人为的示例中,不太可能,但在具有遗留数据库的真实系统中,这种情况会发生),也许是为了完全不同的系统的好处,我们决定创建一个仅包含少数列的 CUSTOMER_SUMMARY 表,并且CUSTOMER_DETAILS 表,包含所有其余列。我们现在应该重命名我们的 Customer 类吗?它从两个表中获取数据,因此我们不再遵守我们的命名约定,但从视图的角度来看,它是客户数据,这正是他们所需要的。我说“不”,名称完全正确,实现细节已经改变,但这对我们的消费者来说并不重要。

类似地,如果我们有 ORDERS、ORDER_LINES、ProductS 和一个保存有关订单信息的类,该类可能会从所有三个表中获取数据,我会将该类称为 Order。如果将来我只需要从订单中获取汇总数据,我可能会使用 OrderSummary 类。我尝试选择一个易于“外部”理解的名称。

Assuming that you mean in the context of a MVC pattern, the Model is outward facing, for manipulation by the Controller and consumption by the View. The names of Model classes should be chosen to help the authors of View and Controller. I don't agree that the names of an implementation detail of the Model (the database tables) is necessarily the correct basis for the names of the Model classes.

To take a simple example: Suppose we have a CUSTOMER table. Then we create a Customer class, all very nice we understand it perfectly. Now suppose that for performance reasons (In this contrived example, unlikely, but in real systems with legacy databases it happens) perhaps for the benefit of a completely different system, we decide to create a CUSTOMER_SUMMARY table containing only a few of the columns, and a CUSTOMER_DETAILS table, containing all the rest of the columns. Should we now rename our Customer class? It takes data from both tables, so we no longer conform to our naming convention, but from the perspective of the View it is the Customer data, it's just what they need. I say "no", the name is exactly correct, the implementation detail has changed, but that is not important to our consumers.

Similarly, if we have ORDERS, ORDER_LINES, PRODUCTS and a class that holds the information about an Order, which is likely to take data from all three tables, I'd call that class Order. If in the future I need summary data taken from ORDERS only I might us a Class OrderSummary. I try to choose a name that is easy to understand from the "outside".

画尸师 2024-12-04 23:29:56

我认为不存在直接的命名约定。您可以根据您的业务使用您的模型的真实域名。假设您想要将 AddressInfo, Street, City 表映射到一个模型(域)类,那么名称将类似于 Address

除此之外,为一个模型(Domain)类映射多个表在实体框架中并不是一种好的做法。因为它会生成非常复杂的查询,从而降低性能

I think there is no straight forward naming conventions as such. you can use the real domain name for your model according to your business. Let say you want to map AddressInfo, Street , City tables in to one model (domain) class then the name will be something like Address.

Other than that mapping several tables for one model (Domain ) class is not a good practice in entity Framework. Because it will generate very complex queries which reduces the performance

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文