当我有一个公共实体时的数据库、数据访问和业务层设计

发布于 2024-12-04 19:23:26 字数 349 浏览 1 评论 0原文

我有一个网站,其中包含很多类型的业务,每个业务都有自己的层,但现在我有一个称为品牌的通用实体。

我是否应该为每个企业品牌信息提供表格,例如:

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 技术交流群。

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

发布评论

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

评论(3

终陌 2024-12-11 19:23:26

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

高速公鹿 2024-12-11 19:23:26

我假设通用实体是指在您网站上的所有企业之间共享的对象。如果是这种情况,您的数据库架构应该反映所有品牌的单个表,但它应该有一个 BusinessID 列,其中包含与其关联业务的外键。

[dbo].[Brands]
ID
BusinessID → [dbo].[Businesses].[ID]
...

[dbo].[Businesses]
ID ← [dbo].[Brands].[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.

[dbo].[Brands]
ID
BusinessID → [dbo].[Businesses].[ID]
...

[dbo].[Businesses]
ID ← [dbo].[Brands].[BusinessID]
...

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.

夏夜暖风 2024-12-11 19:23:26

我会把这些分开。下面有两个选项。您不需要重复具有相同类型数据的表。

选项 1

Brands
{
  ID,
  BusinessID,   (FK to Business.ID)
  Info1,
  Info2
}

Business
{
  ID,
  BusinessName,
  BusinessDesc,
  OtherStuff1,
  OtherStuff2
}

选项 2

Brands
{
  ID,
  Info1,
  Info2
}

Business
{
  ID,
  BusinessName,
  BusinessDesc,
  OtherStuff1,
  OtherStuff2
}

BusinessToBrands
{
  ID,
  BrandsID(FK to Brands),
  BusinessID(FK to Business)
}

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

Brands
{
  ID,
  BusinessID,   (FK to Business.ID)
  Info1,
  Info2
}

Business
{
  ID,
  BusinessName,
  BusinessDesc,
  OtherStuff1,
  OtherStuff2
}

Option 2

Brands
{
  ID,
  Info1,
  Info2
}

Business
{
  ID,
  BusinessName,
  BusinessDesc,
  OtherStuff1,
  OtherStuff2
}

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