Mam następującą strukturę danych:Entity Framework multitenant wspólna architektura dane: pojedyncza kolumna, wiele kluczy obcych
//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;
}
pojawia się następujący błąd:
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.
błąd występuje przy użyciu Fluent Configuration Api :
config.HasRequired(p => p.OtherClass)
.WithMany(oc => oc.SpecialOrders)
.HasForeignKey(p => new { p.TenantId, p.OtherClassId});
Bez numeru referencyjnego OtherClass
w SpecialOrder
Mogę swobodnie tworzyć obiekty bez problemów (w tym SpecialOrder
, SuperSpecialOrder
itp.).
Ktoś ma pojęcie, co się dzieje? Gubię tutaj :(
Edycja widziałem w innych pytań, które ludzie usuwają TenantId z tabel, to nie jest opcją, ponieważ klucze podstawowe nie są unikalne w całej lokatorów i chcemy zachować wspólne architektura danych.
wiem obejście jest posiadanie drugiego TenantId w klasie SpecialOrder, ale to nie wydaje się logiczne, aby mnie.
Myślę, że to ten sam problem, jak ten: http: // stackoverflow.com/questions/10961690/dziedziczenie-i-kompozytu-klucze-zagraniczne-jedna-część-klucza-w-klasie---podstawowej Czy możesz pokazać swoje mapowanie dokładniej? Co to jest 'config'? Przypuszczam, że 'EntityTypeConfiguration' z 'T' =' SpecialOrder', prawda? Jak wygląda mapowanie dla 'Order.Customer'? Czy tworzysz to mapowanie za pomocą 'T' =' SpecialOrder' lub 'T' =' Order '? –
Slauma
Problem pojawia się, gdy określam mapowanie dla zamówienia i zamówienia specjalnego. Następnie traci widok jakiejkolwiek własności zadeklarowanej w klasie bazowej w SpecialOrder. Wydaje się, że to samo pytanie. – Bas