我有以下數據結構:實體框架的多租戶共享數據結構:單立柱,多個外鍵
//property Notification
abstract class BindableBase { }
//base class for all tenant-scoped objects
abstract class TenantModelBase : BindableBase
{
int TenantId;
}
abstract class Order : TenantModelBase
{
Customer Customer; //works: mapped using TenantId and CustomerId
Product Product; //again, works with TenantId and ProductId
string ProductId;
string CustomerId;
}
class Customer: TenantModelBase
{
string CustomerId;
}
class Product : TenantModelBase
{
string ProductId;
}
class SpecialOrder : Order
{
OtherClass OtherClass; //this fails!, see below
string OtherClassId;
}
class SuperSpecialOrder : SpecialOrder { }
class OtherClass : TenantModelBase
{
string OtherClassId;
}
我收到以下錯誤:發生
The foreign key component 'TenantId' is not a declared property on type 'SpecialOrder'. Verify that it has not been explicitly excluded from the model and that it is a valid primitive property.
錯誤使用流利的API配置:
config.HasRequired(p => p.OtherClass)
.WithMany(oc => oc.SpecialOrders)
.HasForeignKey(p => new { p.TenantId, p.OtherClassId});
沒有OtherClass
參考SpecialOrder
我可以自由地創建對象(包括SpecialOrder
,SuperSpecialOrder
等)。
任何人都有線索怎麼回事?我在這裏失去了:(
編輯 我在人們取出從表中TenantId其他疑問看出,這是不是一種選擇,因爲主鍵是不能跨租戶獨一無二的,我們希望保持共享數據架構。
我知道了解決方法是一種在SpecialOrder類第二TenantId,但是這似乎並不符合邏輯的我。
我認爲這是一個像這樣的問題:http:// stackoverflow。com/questions/10961690/inheritance-and-composite-foreign-keys-key-in-base-class-the-part-of-the-key-in-base-class--你能更精確地顯示你的映射嗎?什麼是'config'?我猜'EntityTypeConfiguration'''T' ='SpecialOrder',對吧? Order.Customer的映射如何?你用'T' ='SpecialOrder'還是'T' ='Order'創建這個映射? –
Slauma
2012-08-16 21:48:00
當我爲Order和SpecialOrder指定映射時,就會出現問題。然後它忽略SpecialOrder在基類中聲明的任何屬性。這看起來確實是同一個問題。 – Bas 2012-08-20 06:31:23