我有两个问题,有EF4.2,还有《法典》第一设计办法和基类遗产继承(Table Pertail型)。
(1) 挥发性Api无视基类财产(非不动产)造成EF错误。
看来,我无视流利皮中的说法,没有在我的基类财产上得到适当处理。
class BaseContentElement {
public virtual BaseContentElemnt Parent {get; set;}
public int Id {get;set;}
......
}
class ChapterElement : BaseContentElement {
public virtual CourseElement Course {
get { return base.Parent as CourseElement; } set {base.Parent = value; }
}
......
}
缩略语
var config = new EntityTypeConfiguration<ChapterElement>();
config.Map(m =>
{
m.MapInheritedProperties();
m.ToTable("Chapter", Schema);
});
config.HasKet( ch => ch.Id );
config.Ignore( ch => ch.Parent );
造成Id没有出现在<代码>类中的错误的EF 章 次 页 次
但是,如果是的话,我还要加上关于父母财产的数据说明(NotMapped)。 BaseContentElement , EF的发动机是现成的, DB是创建的。
2) 基地阶级协会的不动产到一个调查表中,造成重复关键插入的错误。
public abstract class BaseListItemElement : BaseContentElement, IComparable
{
public int Id { get; set; }
public int Index { get; set; }
public virtual StaticContentBlockElement Item { get; set; }
public virtual eAnimationDirection AnimeDirectionEnum
{
get
{
if (AnimeDirection != null)
{
return AnimeDirection.EnumValue;
}
return eAnimationDirection.None;
}
set
{
AnimeDirection = AnimationDirection.Lookup[value];
}
}
public virtual AnimationDirection AnimeDirection { get; set; }
......
public class TextListItem : BaseListItemElement {
......
}
In my app I keep a lookup table in memory of all the lookup table values (the app works with the enum eAnimationDirection
and the DB is updated with the AnimeDirection
property). Before I add the records to the DBContext
, I attach the lookup values to the context DbContext.AnimationDirections.Attach(
...... for each item in lookup table ......).
当我加入亚洲开发银行时,在<条码>中出现了重复插入错误(即表)。
If however I move the properties, AnimeDIrection
and AnimeDirectionEnum
to the sub-class, TextListItemElement
, the operations succeed without error...... I have 3 other sub-classes which also share the properties (actually there are two lookup properties on the base class that I share, so it would not be advisable to move the properties to the sub-classes)......
Either this is a bug in EF 4.2 or it may be due to my base class being abstract (Microsoft has a bad history with base abstract classes.......)