且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Entity Framework Core 模型中使用 C# 8.0 可空引用类型?

更新时间:2022-01-17 00:42:11

没有正确的方法来处理不可为 null 的导航属性.

There is no proper way to handle non-nullable navigational properties.

  1. 文档提出了两种方法,但都不是类型安全的.用一个支持字段并抛出 InvalidOperationException.不清楚如何它不同于什么都不做并且有一个 NullReferenceException
  2. 用空原谅运算符抑制它

官方文档链接:https://docs.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#non-nullable-properties-and-initialization