Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在实体框架中,我拥有与数据库中允许 NULL = True 的 SQL 表列相对应的实体属性。当我在 C# 中使用这些属性时,如果值为 null,则会出现异常。那么如何在 EF 中处理这个问题,这发生在所有允许 null 的表列上。
我假设这些列是Nullable在您的 .NET 代码中输入的,因为它们ALLOW NULL = True在数据库中。因此,每次使用这些值时,只要属性为空,就检查PropertyName.HasValue()哪个返回。false
Nullable
ALLOW NULL = True
PropertyName.HasValue()
false