English 中文(简体)
两个问题涉及EF 4.2和继承的同族关系
原标题:A couple of issues with EF 4.2 and inherited class association properties

我有两个问题,有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.......)

问题回答

这两个问题完全无关,因此不应一并提出。 第二点应该单独提出,并附上显示你如何随附/增加实体的编码样本,因为问题大部分没有解决,你的说明实际上没有说明这一点——真正的可再生守则就是这样做的。

对第一个问题的答复: 是不可能的。 一旦基类的任何部分被绘制成地图,你就不能在衍生类别中忽略。 衍生物类别必须包含在基类中绘制的所有特性。





相关问题
Howto get started with C# 4.0 and .NET 4.0?

I don t want to download Visual Studio 2010. How can I start studying (not developing real applications) C# 4.0 and .NET 4.0 with just a text editor? Can I just download C# 4.0 compiler and .NET 4.0 ...

Mocking Framework with C# 4.0 Support?

Anybody know of a mocking framework that supports C# 4.0? Doesn t matter which one ATM, just need something that will work.

Unit Testing interface contracts in C#

Using the Code Contracts tools available in VS2010 Beta 2, I have defined an interface, a contract class for that interface and two classes that implement the interface. Now when I come to test the ...

How to Iterate Through Array in C# Across Multiple Calls

We have an application where we need to de-serialize some data from one stream into multiple objects. The Data array represents a number of messages of variable length packed together. There are no ...

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program. import ConfigParser C# code: using System; using System.Collections.Generic; using ...

i cant understand the following code

Matrix<float> trainData2 = trainData.GetRows(intVar >> 1, intVar, 1); intVar is integer type... please help me to understand this code.

热门标签