简体   繁体   中英

Set default Date value during Model Generation in Code First Entity Framework Fluent API

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 ?

You can assign the property in the parameter less constructor.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM