Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default value in EF designer datetime

Tags:

Trying to set the default value of a datetime field to take current time. In SQL's field designer i'd use getdate(). What should i use in Entity Framework's designer?

thx

like image 606
justSteve Avatar asked Jan 13 '11 18:01

justSteve


2 Answers

Set 'StoredGeneratedPattern' to Computed against the field in the EDMX.

You still need the default value in SQL Server though, the above setting will ensure EF honour's that.

like image 147
RPM1984 Avatar answered Sep 28 '22 08:09

RPM1984


Building upon RPM1984's answer:

  1. Select the field that has the default value,Created_On in my example, within your EDMX file
  2. Go to the Properties panel
  3. Select the StoreGeneratedPattern attribute
  4. Then change the value to Computed

EDMX to Properties panel

like image 32
Adam Huffman Avatar answered Sep 28 '22 06:09

Adam Huffman