尝试在Entity Framework Core中保存模型会引发错误“对象引用未设置为对象的实例”

问题描述

我正在尝试保存以下模型,我做对了所有事情

  1. 我检索模型
  2. 设置属性
  3. 然后保存它。

See the error here

我检查了模型是否不为null,所以我不明白为什么我仍然会收到错误消息。

这是我的代码

foreach (var F in Q.Fields)
{
    NumberValue nValue = _context.NumberValues
                                 .Where(m => m.FieldId == F.Id && m.ReportId == form["ReportId"])
                                 .SingleOrDefault();

    nValue.Data = 2;

    _context.Entry(nValue).State = EntityState.Modified;
    _context.SaveChanges();
}

我返回了对象本身,它显示了所有数据,这意味着它不为空

See the Json representation of the object here

当我返回<nValue.GetType()>时,这就是我得到的:

DataSystem.Models.GLM.NumberValue,DataSystem,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null

有人可以告诉我我在做什么错吗?我已经为这个问题苦苦挣扎了两天了。...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...