In my SQL Server database schema, I have a data table with a date field that contains a default value
CONVERT(VARCHAR(10), GETDATE(), 111)
which is ideal for automatically setting the date in a new record when manually entering records into the database.
The problem is that when using the Entity Framework and matching the Date field, the Entity Framework inserts the default DateTime.Min when instantiating the object.
I cannot match the Date field with a null DateTime value, that is, DateTime ?, and I cannot use CONVERT or DateTime.Now.Today in the standard Entity Designer value, since it only accepts hard-coded constant values.
I can, of course, explicitly set the DateTime field in C # whenever an object is created, either explicitly in code, in the constructor of a partial class, or even during a change event.
Are there other ways to achieve what I want when the default value that is stored in the database table is used instead?
c # entity-framework
Justin Oct 22 '09 at 18:59 2009-10-22 18:59
source share