将可为空的属性的EntityFrameworkCore从2.1更新为2.2后,发生System.InvalidOperationException

时间:2019-01-17 17:21:53

标签: entity-framework .net-core entity-framework-core

dotnetcoreEF 2.1升级到2.2之后,我得到了System.InvalidOperationException

我启用了options.EnableDetailedErrors(true);,它给出了一条稍微有用的消息,显示了属性名称:

"An exception occurred while reading a database value for property
'Sale.AuthorId'. The expected type was 
'System.Nullable`1[System.Int32]' but the actual value was null."

我的查询很简单:

var test = await _context.Blogs.ToListAsync();

在模型中,属性定义为:

[ForeignKey("Author")]
public int? AuthorId { get; set; }
public virtual Author Author { get; set; }

这以前在2.1中有效。我已将该属性标记为可选(int?),因此很困惑为什么要抛出该属性。

0 个答案:

没有答案