更新时间:2023-09-18 18:52:16
这很讨厌,但很简单:
检查 O/R-Designer 中所有字段的数据类型是否与 SQL 表中的数据类型匹配.双重检查是否可以为空!一个列应该在 O/R-Designer 和 SQL 中都可以为空,或者在两者中都不能为空.
Check if the data types for all fields in the O/R-Designer match the data types in your SQL table. Double check for nullable! A column should be either nullable in both the O/R-Designer and SQL, or not nullable in both.
例如,NVARCHAR 列title"在您的数据库中被标记为 NULLable,并且包含值 NULL.即使该列在您的 O/R-Mapping 中被标记为 NOT NULLable,LINQ 也会成功加载它并将 column-String 设置为 null.
For example, a NVARCHAR column "title" is marked as NULLable in your database, and contains the value NULL. Even though the column is marked as NOT NULLable in your O/R-Mapping, LINQ will load it successfully and set the column-String to null.
当字段的数据类型与 SQL 中的数据类型不匹配,或者字段丢失时,也会出现相同的症状,因为 LINQ 将无法确保 SQL 数据在读取数据后没有发生变化.
The same symptom will appear when the data types of a field does not match the data type in SQL, or if fields are missing, since LINQ will not be able to make sure the SQL data has not changed since reading the data.