linq to sql string property from non-null column with default
Posted
by Barry Fandango
on Stack Overflow
See other posts from Stack Overflow
or by Barry Fandango
Published on 2010-03-13T17:41:57Z
Indexed on
2010/03/13
17:45 UTC
Read the original article
Hit count: 263
linq-to-sql
I have a LINQ to SQL class "VoucherRecord" based on a simple table. One property "Note" is a string that represents an nvarchar(255) column, which is non-nullable and has a default value of empty string ('').
If I instantiate a VoucherRecord the initial value of the Note property is null. If I add it using a DataContext's InsertOnSubmit method, I get a SQL error message:
Cannot insert the value NULL into column 'Note', table 'foo.bar.tblVoucher'; column does not allow nulls. INSERT fails.
Why isn't the database default kicking in? What sort of query could bypass the default anyway? How do I view the generated sql for this action?
Thanks for your help!
© Stack Overflow or respective owner