How to use the default Entity Framework and default date values

后端 未结 8 785
说谎
说谎 2020-12-15 23:53

In my SQL Server database schema I have a data table with a date field that contains a default value of

CONVERT(VARCHAR(10), GETDATE(), 111)
<
8条回答
  •  無奈伤痛
    2020-12-16 00:35

    You can use a database trigger, which, on insertion, checks if the inserted value is DateTime.MinValue (01.01.0001) and replaces it with the calculated value you desire. This MSDN article describes how to create a trigger.

    A little "flaw": with this solution you would have to store the new object to the database and read it back afterwards to update your object with the calculated value.

提交回复
热议问题