user610217
user610217

Reputation:

Entity Framework DateTime defaults

Is there a way to automagically map a DateTime.MinValue to a null value in the data layer and vice-versa?

I am trying out EF6. I want to eventually target SQL Server 2005 servers, so the DATETIME2 type is something I want to avoid.

Upvotes: 0

Views: 890

Answers (2)

Pawel
Pawel

Reputation: 31610

EF does not support mapping min/max/specific values to null through mapping/fluent API. You could override SaveChanges() and inspect/update entities on save but it would be more involved

Upvotes: 1

tsdaemon
tsdaemon

Reputation: 1557

There two way to solve it:

  1. You can set Default Value=DateTime.MinValue for your datetime field in model editor.
  2. You can set StoreGeneratedPattern=Identity for your datetime field in model editor and set default value for that field in SQL table.

Upvotes: 0

Related Questions