Default value for Datetime column

Asked

Viewed 134 times

2

I have a table that has the field DataRegistro of the kind Datetime. I am using Entityframework to generate the database (I am not using code first) add the property Computed for the column to be filled automatically, but I keep getting message and error when trying to insert a new object.

I would like to solve directly by EF without having to add scripts/Trigger in the bank to fix the problem.

Any suggestions?inserir a descrição da imagem aqui

1 answer

4


Like you’re wearing it Model first an alternative would be to create a class partial and create a constructor that initializes this field. Ex.:

public partial CursoDisciplina 
{
    public CursoDisciplina()
    {
        this.DataRegistro = DateTime.Now;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.