CTP5 Code First TPH与抽象类 [英] CTP5 Code First TPH with abstract classes

查看:101
本文介绍了CTP5 Code First TPH与抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 您好

以下代码不会运行它 - 产生跟随它的错误。如果我删除EntityA的定义,或者如果我使EntityB非抽象,那么它可以正常工作。这个问题似乎源于同一个超类的抽象和非抽象子类

The following code will not run it - produces the errors following it. If I remove the defintion for EntityA, or if I make EntityB non-abstract, it works OK. The problem seems to to stem from having both an abstract and a non-abstract subclasses of the same super-class.

namespace EFCodeFirstTest
{
public class Entity
{
public Guid Id {getset;}
}

public class EntityA : Entity { }

public abstract class EntityB : Entity { }

public class EntityC : EntityB { }


public class MyContext : DbContext
{
public DbSet<Entity> Entities { getset; }
}

class Program
{
static void Main(string[] args)
{
var ctx = new MyContext();
ctx.Entities.Add(new EntityC { Id = Guid.NewGuid() });
ctx.SaveChanges();
}
}
}

(6,10):错误3034:从第6,18行开始映射片段时出现问题:2具有不同键的实体映射到同一行。确保这两个映射片段不会将具有不同
键的两组实体映射到两个重叠的行组。

(12,10):错误3034:从第12,18行开始映射片段时出现问题:具有不同键的两个实体映射到同一行。确保这两个映射片段不会将具有不同
键的两组实体映射到两个重叠的行组。

(23,10):错误3034:从第18,23行开始映射片段时出现问题:具有不同主键的两行映射到同一实体。确保这两个映射片段不会将具有相同
键的两组实体映射到两个重叠的行组。

推荐答案

嗯,我刚刚运行了你的代码(作为一个控制台项目),没有错误。

Hmmm, I just ran your code (as a Console project), and got no errors.

我添加了对EntityFramework的引用,以及一个"using System.Data"。实体",按下f5,没有错误,出现命令窗口。

I added a reference to EntityFramework, and a "using System.Data.Entity", pressed f5, no errors, a command window appeared.

你能验证你实际上是在运行CTP5吗?或者除了上面显示的内容之外还有更多代码吗?

Can you verify that you are actually running with CTP5? Or is there more code in addition to what you show above?


这篇关于CTP5 Code First TPH与抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆