我用Google搜索无效,所以假设无法使用Entity Framework(6)在实体模型派生的类上调用 Attach()
?我'm using the '数据库第一'方法 .
例如,插入类 Dog
如下:
public partial class Animal //this will insert fine.
{
public long AnimalId
}
public class Dog:Animal //this will not insert.
{
}
我目前收到错误:
实体类型Dog不是当前上下文的模型的一部分 .
完整代码:
public class Dog : Animal
{
}
using (var context = new CalibrationManagerEntities())
{
var a = new Animal() { AnimalId = 0 };
var b = context.Entry(a); //works
var c = new Dog() { AnimalId = 0 };
var d = context.Entry(c); //throws exception
}
1 回答
把狗当成动物应该可以解决问题