gpt4 book ai didi

c# - 从 ObjectStateEntry 检索值时出错

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:03 24 4
gpt4 key购买 nike

我尝试根据 this 创建数据库教程。

这是我的类(class):

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; }
}

主要

var sb = new SubFile{ fileName = "test.doc" };
sb.secondName= "test2.doc";

using (var db = new MyContext())
{
db.SubFile.Add(sb);
db.SaveChanges();
}

尝试保存后出现错误:

Error retrieving values from ObjectStateEntry. See inner exception for details.

最佳答案

我内心的异常是所引用的对象类型不支持尝试的操作

将新实体添加到数据库后,在我的数据库上下文中调用 SaveChanges 时会发生错误。

为了解决我的问题,我不得不更改我的实体,以便将一个复杂类型 IPAddress 改为一个字符串。

关于c# - 从 ObjectStateEntry 检索值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19812100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com