How do I ensure Linq to Sql doesn't override or violate non-nullable DB default values?

前端 未结 4 1648
天命终不由人
天命终不由人 2020-12-09 18:35

I have an SQL Server DB with a table with these fields:

  1. A bit with the default value 1, NOT NULL.
  2. A smalldatetime
4条回答
  •  天命终不由人
    2020-12-09 18:41

    I've run into the same problem, bzlm, and come to the same conclusion. There's simply no good way to get non-nullable fields with DB-assigned default values working with Linq To Sql.

    The work around I've gone with is to add a SetDefaults() method very similar to the one Robert Paulson linked to on CodeProject and call it in the default constructor of my table entity base class. It works well for me, because 95% of the time, I'm setting a 0, empty string, or getdate().

提交回复
热议问题