FransBouma / LinqToSQL2

Official Linq to SQL fork. A complete ORM which is backwards compatible with Linq to SQL but with new features.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Omit null valued columns on insert so default values are inserted instead

FransBouma opened this issue · comments

See e.g. : http://stackoverflow.com/q/2555206

It's a bit of a problem now as an entity with fields which are not initialized (so are null), will get a value inserted (null) so defaults don't work.

It's not an ideal situation, fields which are not nullable but aren't initialized with a value now will not get the default set so the user has to specify a value in the client, which might differ from the value in the default constraint. Unfortunately with POCOs this isn't always determinable. Try to find a way to see whether a property has been set in the poco and use that info to determine whether a field has to be inserted.

If the mapping attribute / xml element for the column contains IsDbGenerated=true, (see: https://msdn.microsoft.com/en-us/library/system.data.linq.mapping.columnattribute.isdbgenerated%28v=vs.110%29.aspx) Linq to Sql doesn't insert a NULL, and will also read the DB value. So this issue is not really an issue.