开发者

LINQ-to-SQL - The null value cannot be assigned to a member with type

开发者 https://www.devze.com 2023-03-09 19:05 出处:网络
I have an issue with a LINQ query I am working on. This has worked perfect for a while, but we did a rollback of the database and now it doesn\'t work.

I have an issue with a LINQ query I am working on. This has worked perfect for a while, but we did a rollback of the database and now it doesn't work.

Basically, I'm inserting a new row into a table which has an autogenerating BigInt PK. But when SubmitChanges is called 开发者_StackOverflowI get this error:

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

I've looked at the generated SQL, and the issue seems to likely revolve arond this after the insert:

SELECT CONVERT(BigInt, SCOPE_IDENTITY()) AS [value]

This seems to be returning null, but I have no idea why. Both the table and the LINQ dmbl are set up correctly for autogenerating PK's.

Any ideas?

EDIT: After some debugging, including trying an insert manually in SQL as someone kindly suggested, I've stumbled upon a very strange issue -

'Column or expression 'Outstanding' cannot be updated'

Outstanding is a non-nullable decimal(9,2) field


Take a look at this thread - someone else had the same error as you, same situation. It turns out that there was an issue with running the actual insert, which resulted in no record being inserted. Then when SCOPE_IDENTITY() was called, it returned null, since no record was inserted.

Try running a straight Insert of the same values into the table through your Sql Management tool, and see if the row inserts properly. There might be some other issue that is preventing this (aside from the autogenerating PKs), which would be the root cause of the issue.

0

精彩评论

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