如何在项目中为表创建类 [英] How to create classes for tables in project

查看:55
本文介绍了如何在项目中为表创建类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是正确的方法?
1.为数据库中的所有表创建单个类文件.
2.为数据库中的所有表创建不同的2个类.

在此先感谢您.

What is right approach?
1. Create a single class file for all the tables in database.
2. Create different 2 classes for all the tables in database.

Thanks in advance.

推荐答案

也许您会在此方面获得帮助 [^ ]


这取决于在应用程序上.通常,数据在屏幕上的显示方式与数据在数据库中的存储方式不同.因此,应用程序中使用的类应取决于数据在屏幕上的显示方式.存储过程/查询应以易于将数据转换为此类对象的方式返回它.

例如,您可能有一个客户和地址"表,但是在UI中,您需要在单个GridView中显示客户名称"和地址".在这种情况下,使用只包含两个表中必需字段的类似乎是更好的方法.

在您的情况下,如果从表中获取所有列是有意义的,则仅出于可维护性的考虑而对每个表保留类.对我来说,这也意味着您所有的查询都可能看起来像select * from SomeTable where SomeCondition.
It depends on the application. Often, the way data is displayed on the screen is different from the way it is stored in the database. Hence the classes used in the application should depend on the way data is displayed on the screen. The stored procedures/queries should return it in a way that data can be easily converted to this class objects.

For instance, you may have a Customer and Address table but in the UI you need to display Customer name and Address in a single GridView. In this case, having a class with only needed fields from both the tables seem better approach.

In your case, if getting all the columns from tables make sense, then keep on class per table just for sake of maintainability. This also means (to me) that all of your queries might look like select * from SomeTable where SomeCondition.


这篇关于如何在项目中为表创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆