C# 从ObjectStateEntry检索值时出错
我尝试根据教程创建C# 从ObjectStateEntry检索值时出错,c#,entity,C#,Entity,我尝试根据教程创建数据库 这是我的班级: public abstract class File { [Key] public string fileName { get; set; } public double size{ get; set; } } public class SubFile: File { public string secondName{ get; set; } } public class MyContext : DbContext {
数据库
这是我的班级:
public abstract class File
{
[Key]
public string fileName { get; set; }
public double size{ get; set; }
}
public class SubFile: File
{
public string secondName{ get; set; }
}
public class MyContext : DbContext
{
public DbSet<SubFile> subFile{ get; set; }
}
尝试保存后出现错误:
从ObjectStateEntry检索值时出错。有关详细信息,请参见内部异常
细节
我的内部异常是引用的对象类型不支持尝试的操作
将新实体添加到数据库后,在我的数据库上下文上调用SaveChanges时会发生错误
为了解决我的问题,我必须更改实体,使复杂类型IPAddress改为字符串。详细信息部分是什么?@user1860934,是的,内部异常。内部异常的文本是什么?nner异常为null,消息是所引用的对象类型不支持尝试的操作。我们遇到了相同类型的错误。这是因为edmx类中的额外属性与数据库中的表不匹配。
var sb = new SubFile{ fileName = "test.doc" };
sb.secondName= "test2.doc";
using (var db = new MyContext())
{
db.SubFile.Add(sb);
db.SaveChanges();
}