How to use the default Entity Framework and default date values

后端 未结 8 749
说谎
说谎 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:38

    I just ran into this - I worked around it by setting the date (the field I needed auto generated) in the constructor of the Entity using a partial method. Whether this is Ideal or whether it works in all cases is yet to be seen, but it has fixed my problem so far.

    0 讨论(0)
  • 2020-12-16 00:38

    Just happened to cross through this issue. Entity Framework do not support default values on its own. You need to set the property StoreGeneratedPattern = Computed on the column in the Edmx file entity. The default value what you set in the Database will then precedence on what EF sets by default i.e. DateTime.Min

    0 讨论(0)
提交回复
热议问题