多重繼承我試圖映射在TPC風格使用實體框架一些類,並得到了以下錯誤:與實體框架TPC
Error: The type 'A' cannot be mapped as defined because it maps inherited properties from types that use entity splitting or another form of inheritance. Either choose a different inheritance mapping strategy so as to not map inherited properties, or change all types in the hierarchy to map inherited properties and to not use splitting.
當我用下面的類會出現此錯誤:
public abstract class BaseEntityTest
public abstract class BaseEntityTest2 : BaseEntityTest
public abstract class BaseEntityTest3 : BaseEntityTest2
public class A: BaseEntityTest3 // this class is the only one with a table in the db
在OnModelCreating方法中,我添加了以下代碼以獲得TPC映射
modelBuilder.Entity<A>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("A");
});
當我從結構中排除BaseEntityTest2(因此A只從BaseEntityTest而不是BaseEntityTest2繼承)時,錯誤消失。這是否意味着不可能創建這個映射或者我只是錯過了什麼?
編輯:類
屬性:爲EF 4.3.1及更早版本發生
public abstract class BaseEntityTest
{
[Key]
public Guid Id { get; set; }
public String Info { get; set; }
[Required]
public DateTime CreationDate { get; set; }
[Required]
public String CreationUser { get; set; }
[Required]
public DateTime ModificationDate { get; set; }
[Required]
public String ModificationUser { get; set; }
[ConcurrencyCheck]
[Required]
public int LockVersion { get; internal set; }
}
public abstract class BaseEntityTest2 : BaseEntityTest
{
[Required]
public string Name { get; set; }
public string Description { get; set; }
}
public abstract class BaseEntityTest3: BaseEntityTest2
{
[Required]
public DateTime FromDate { get; set; }
public DateTime ThruDate { get; set; }
}
public class A: BaseEntityTest3{
public String Test { get; set; }
}
這是全貌嗎?在我住的地方工作得很好:)(VS2012,EF 5)。 –
我試過這個使用EF 4.3.1(VS 2012) – Eggi
你有什麼屬性在你的課堂上? –