Default value for column of type Datetime

2

I have a table that has the DataRegistro field of type Datetime . I am using EntityFramework to generate the database ( I am not using the code first ) and I am adding the Computed property so that the column is populated automatically, but I still get error message when trying insert a new object.

I would like to resolve directly from EF without having to add scripts / trigger to the database to correct the problem.

Any suggestions?

    
asked by anonymous 01.09.2015 / 03:52

1 answer

4

As you are using Model first an alternative would be to create a partial class and create a constructor that initializes this field. Ex.:

public partial CursoDisciplina 
{
    public CursoDisciplina()
    {
        this.DataRegistro = DateTime.Now;
    }
}
    
01.09.2015 / 04:26