开发者

Naming pattern for model which access multiple tables

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 sta开发者_开发问答ndard for them?


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".


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜