我在数据库中有以下模式:
BillingReferences (ReferencingType tinyint, ReferencingId tinyint, ReferencedType tinyint, ReferencedId tinyint, IsActive bit) - 所有字段(除了IsActive)都是唯一索引的一部分。
BillingType (BillingTypeId tinyint, Name varchar(50))
ReferencingType和ReferencedType是BillingTypes的外键。 BillingTypes包含以下行:
BillingTypeId | Name 1 | Labels
2 | Countries
3 | PaymentProviders
4 | PaymentOptions
5 | Banks
ReferecingId和ReferencedId表示以下实体之一的ID(取决于Referenced/Referencing Type):
Banks (BankId tinyint, Name varchar(50)) Countries (CountryId tinyint, Name varchar(50)) Labels (LabelId tinyint, Name varchar(50)) PaymentProviders (PaymentProviderId tinyint, Name varchar(50)) PaymentOptions (PaymentOptionId tinyint, Name varchar(50))
将来每个实体都将添加更多不同的列,但现在这就是简单的模式。
每个实体(除了国家)与国家之间存在(1-)的联系。 标签与银行、支付提供商和支付选项之间存在(1-)的联系。 支付提供商与支付提供商之间存在(1-*)的联系
因此,例如,如果我想将BankId 201的银行连接到CountryId 3003的国家中,则在BillingReferences中会有一个记录如下: ReferencingType = 5 ReferencingId = 201 ReferencedType = 2 ReferencedId = 3003 IsActive = 1
我们没有为每种类型的连接/参考表进行连接,因为考虑到可扩展性-如果我们想要添加另一个实体,我们只需添加其表并在BillingReferences和BillingType中添加记录即可。
问题是我无法在BillingReferences和每个实体之间配置有条件的外键,而且似乎我也无法使用EntityFramework进行配置/映射...
BillingReferences (ReferencingType tinyint, ReferencingId tinyint, ReferencedType tinyint, ReferencedId tinyint, IsActive bit) - 所有字段(除了IsActive)都是唯一索引的一部分。
BillingType (BillingTypeId tinyint, Name varchar(50))
ReferencingType和ReferencedType是BillingTypes的外键。 BillingTypes包含以下行:
BillingTypeId | Name 1 | Labels
2 | Countries
3 | PaymentProviders
4 | PaymentOptions
5 | Banks
ReferecingId和ReferencedId表示以下实体之一的ID(取决于Referenced/Referencing Type):
Banks (BankId tinyint, Name varchar(50)) Countries (CountryId tinyint, Name varchar(50)) Labels (LabelId tinyint, Name varchar(50)) PaymentProviders (PaymentProviderId tinyint, Name varchar(50)) PaymentOptions (PaymentOptionId tinyint, Name varchar(50))
将来每个实体都将添加更多不同的列,但现在这就是简单的模式。
每个实体(除了国家)与国家之间存在(1-)的联系。 标签与银行、支付提供商和支付选项之间存在(1-)的联系。 支付提供商与支付提供商之间存在(1-*)的联系
因此,例如,如果我想将BankId 201的银行连接到CountryId 3003的国家中,则在BillingReferences中会有一个记录如下: ReferencingType = 5 ReferencingId = 201 ReferencedType = 2 ReferencedId = 3003 IsActive = 1
我们没有为每种类型的连接/参考表进行连接,因为考虑到可扩展性-如果我们想要添加另一个实体,我们只需添加其表并在BillingReferences和BillingType中添加记录即可。
问题是我无法在BillingReferences和每个实体之间配置有条件的外键,而且似乎我也无法使用EntityFramework进行配置/映射...
我找不到任何使用这种类型实现的教程或示例。我是否需要为每个连接创建一个参考表,还是有一种方法可以使用EntityFramework进行配置?
谢谢帮忙 :)