有没有人有任何处理XSD数据集抛出的ConstraintExceptions的技巧?
这是神秘消息的例外:
System.Data.ConstraintException : Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Run Code Online (Sandbox Code Playgroud) 所以我在这里有一个奇怪的困境.我的SQL表被设置为允许我的ZipCode列的空值,如下所示:
CREATE TABLE [dbo].[Companies]
(
[CompanyId] BIGINT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] NVARCHAR(100) NOT NULL,
[Address] NVARCHAR (100) NULL,
[City] NVARCHAR (50) NOT NULL,
[State] NVARCHAR (2) NOT NULL,
[ZipCode] INT NULL,
[PhoneNum] BIGINT NULL,
[CreatedDate] DATETIME2 NOT NULL DEFAULT GetDate()
)
Run Code Online (Sandbox Code Playgroud)
这应该让ZipCode的值为NULL,对吗?好吧,显然不是......
我一直收到这个错误:
EntityFramework.dll中出现"System.Data.ConstraintException"类型的异常但未在用户代码中处理附加信息:"Company"上的"ZipCode"属性无法设置为"null"值.您必须将此属性设置为类型为"System.Int32"的非null值.
任何人都可以想到为什么会这样做?我检查并仔细检查了我的数据库项目和我的本地数据库,它们都匹配.我的所有单元测试都通过了,所以我在这里几乎不知所措.
任何帮助,将不胜感激!
我有一个数组,其中包含最多20个字符的字符串:
subtype c_string is string(1..20);
type string_array is array (natural range 1..100) of c_string;
Run Code Online (Sandbox Code Playgroud)
当我尝试将字符串分配给string_array的位置时,如果字符串不是20个字符长,则会出现以下错误:
提出CONSTRAINT_ERROR :( ...)长度检查失败
这是导致问题的代码行:
str_a: string_array;
(....)
str_a(n) := "stringToAssign" --Causes error
Run Code Online (Sandbox Code Playgroud)
避免这种情况的最佳方法是什么?