当我有一个公共实体时的数据库、数据访问和业务层设计
我有一个网站,其中包含很多类型的业务,每个业务都有自己的层,但现在我有一个称为品牌的通用实体。
我是否应该为每个企业品牌信息提供表格,例如:
DB Table
Business1_BrandsInfo
....................
DB Table
Business2_BrandsInfo
...etc ?
当然,我将为每个企业的每个品牌信息拥有一个单独的企业实体。
或者我应该有一个公用表并为每个企业添加一个 id 来定义该品牌属于哪个企业。
这几个业务不相关,但无论业务类型如何,每个品牌都有相同的典型信息,而且我的网站上有 5 种不同类型的业务。
I have a website that will contain a lot of types of businesses, each business has it's own layers, but now I have a common entity that's called Brand.
Should I have table for each business brand info, like:
DB Table
Business1_BrandsInfo
....................
DB Table
Business2_BrandsInfo
...etc ?
and of course I'll have a seperate business entity for each Brand info for each business.
Or should I have one common table and add an id for each business to define to which business does this brand belongs.
The several business is not related but I have the same typical info for each brand regardless the type of the business, and I have like 5 different types of business on my site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
simple :如果每个表都有相同的属性,那么您可以将其放入 1 个表中并通过 TypeId 列识别它们。
如果您有超过 1 种类型,那么您还需要超过 1 个实体来满足这些表的要求。
用于识别的类型也将在类中。
请注意,如果明天您将添加特定列来输入“1”,那么您将会遇到问题......
simple : if it has the same properties for each table so you can put it in 1 table and recognize them by TypeId column.
if you have more than 1 type then you'll need also more than 1 entities to content these tables.
the type for recognition will be also in the class.
please be aware that if tomorrow you will add a specific column to type "1" then you will have a problem...
我假设通用实体是指在您网站上的所有企业之间共享的对象。如果是这种情况,您的数据库架构应该反映所有品牌的单个表,但它应该有一个 BusinessID 列,其中包含与其关联业务的外键。
您可以根据需要添加任意数量的企业和品牌,但稍后,如果您想要因企业或品牌而异的自定义属性,则必须更改该架构,或者您必须设计一些其他方法那些自定义字段。
I assume by common entity you mean an object that is shared amongst all businesses in your website. If this is the case your database schema should reflect a single table for all Brands, but it should have a BusinessID column with a foreign key to its associated business.
You could add as many businesses and brands as you want, but later on though if you want custom properties that differ from business to business or brand to brand, then that schema would have to change, or you would have to devise some other method for those custom fields.
我会把这些分开。下面有两个选项。您不需要重复具有相同类型数据的表。
选项 1
选项 2
I would split these out. Here are two options below. You don't need to repeat tables that will have the same type of data.
Option 1
Option 2