开发者

Linq to SQL with unique index using ignore duplicate keys option and an Identity column

_db.Comme开发者_开发技巧nts.InsertAllOnSubmit(comments);
_db.SubmitChanges();

There is a unique index on this table with IGNORE_DUP_KEY = ON, i know that i'm inserting duplicates i just want to ignore them, i'd rather not check each record manually, as this will be slower.

It throws the following:

InvalidOperationException: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.

I'm assuming this is because the value returned to L2S for the primary key field (it's an IDENTITY Column) is null. To me this seems almost like a bug.

Anybody got any ideas, other than individual insert with try/catch or manual checking?


You can change the property to be nullable. This seems more like a work around than a solution. You can change it in the generatedc code (bad idea) or create a subclass and the new keyword.

int? ID;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜