我在数据库中有以下架构:
- BillingReferences (ReferenceType tinyint , ReferencingId tinyint , ReferencedType tinyint , ReferencedId tinyint , IsActive bit ) - 其中所有字段(IsActive 除外)都是唯一索引的一部分。
- BillingType (BillingTypeId tinyint , 名称varchar(50) )
ReferencingType 和 ReferencedType 是 BillingTypes 的外键。BillingTypes 包含以下行:
计费类型 ID | 姓名
1 | 标签
2 | 国家
3 | 支付提供商
4 | 付款方式
5 | 银行
ReferencedId 和 ReferencedId 表示以下实体之一的 Id(取决于引用/引用类型):
- 银行(BankId tinyint,名称varchar(50))
- 国家(CountryId tinyint,名称varchar(50))
- 标签(LabelId tinyint,名称varchar(50))
- PaymentProviders(PaymentProviderId tinyint,名称varchar(50))
- PaymentOptions (PaymentOptionId tinyint , 名称varchar(50) )
将来每个实体都会添加更多不同的列,但现在这是简单的模式。
每个实体(国家除外)与国家之间都有(1- ) 的连接。标签与银行、PaymentProviders 和 PaymentOptions有 (1-) 的连接。并且 PaymentProviders 与 PaymentProviders 有 (1-*) 的连接
例如,如果我想将 BankId 为 201 的银行连接到 CountryId 为 3003 的国家/地区,我将在 BillingReferences 中有一条如下所示的记录:ReferencingType = 5 ReferencingId = 201 ReferencedType = 2 ReferencedId = 3003 IsActive = 1
出于可扩展性考虑,我们没有为每种类型的连接创建连接/引用表 - 如果我们想要添加另一个实体,我们所要做的就是添加它的表并在 BillingReferences 和 BillingType 中为其添加记录。
问题是我无法在 BillingReferences 和每个实体之间配置条件外键,我似乎也无法使用 EntityFramework 配置/映射它......
我找不到任何使用这种实现类型的教程或示例。我是否必须为每个连接创建一个参考表,或者有没有办法使用 EntityFramework 来配置它?
谢谢您的帮助 :)