2

I am using VS 2013 C# Entity framework 6.0.0.0 Code First. I have Class like this below.

public class Om_Category
{
    public DateTime CreationDate { get; protected set; }
}

So far I am manually assigning the DateTime.Now value to this Property.

I found many articles on Google that only says to use Migration.

Is there any way in EF Code First Fluent API with which we can set the default value(getdate()) for CreationDate Column while model generation ?

Pankaj
  • 9,749
  • 32
  • 139
  • 283

1 Answers1

-1

You can assign the property in the parameter less constructor.

I have done like this in the ctor of a root class .

  • Perhaps this is for you [http://stackoverflow.com/questions/3879011/entity-framework-sql2008-how-to-automatically-update-lastmodified-fields-for-e](http://stackoverflow.com/questions/3879011/entity-framework-sql2008-how-to-automatically-update-lastmodified-fields-for-e) – D. Lucazeau Sep 29 '15 at 13:01
  • And you will see there is no better solution, may be in another EF release. – D. Lucazeau Sep 29 '15 at 13:08