Is there an easy way to make EntityFramework use SQL default values?

前端 未结 3 1749
轻奢々
轻奢々 2020-12-03 17:23

For example, most of my entities have DateCreated and DateModified fields. The defaults to these are set to GetUtcDate() in SQL Server.

If I try and create an entity

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 18:12

    You must set StoreGeneratedPattern for those properties to Identity for DateCreated and Computed for DataModified. It is available in designer. Once you do that you cannot modify those values in your application - only database can set those properties. I wrote about this some article because this feature had bug before VS2010 SP1 but there are reports that it still doesn't work sometimes.

提交回复
热议问题