I have a SQL table that contains a DateTime column with the value GetDate by default ()
Instead of using the local date and time of the computer the console app is running on, I would like entity framework to utilize the SQL date and time (the SQL server is 1 hour behind).
Additionally, since the column does not permit null values, when I enter the date 1/1/0001, I receive the following error:
An out-of-range value was produced by converting a datetime2 data type to a datetime data type. The statement has come to an end.
By telling EF not to insert a value for that column, the database will generate the field's default value. Remember that passing some values won't be possible.
Simply add the following to your DbContext class if you're utilizing the Fluent API:
modelBuilder.Entity<EntityName>() .Property(p => p.PropertyName) .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);