none
Problem when I was not Passing a value to the ModifiedDate column in Entity Framework RRS feed

  • Question

  • Hi, I'm learning EF these days, and came across a problem. I'm using AdventureWorksLT database and in the SalesLT.Customer I have a column ModifiedDate which is NOT NULL and has a default binding in the database level with GETDATE().

    In my CustomerEntity when I write a code like this

    using (var _container = new AWLiteEntityContainer())
       {
        Customer c = new Customer()
        { FirstName = "MyName", LastName = "MyLastname", 
        PasswordHash= "DFIFERE8748924DFDD4DFD234", PasswordSalt = "2342DFS", ModifiedDate = DateTime.Now,
        };
    
        _container.Customers.AddObject(c);
        _container.SaveChanges();
       }
    

    It works fine, but when I do not pass a ModifiedDate value from my code considering the database will handle that by the defined default constraint, it throws an error that

    " {"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."} "

    This is because the C# DateTime.MinValue is not in the range of the SQL DataTime value. But why this is happening, since I hace defined the DateTime defined as a Default constraint in my database I don't want to pass that from the code.

    If the ModifiedDate is NULL then there is no problem, because entity model is not passing a value.

    How can I solve the problem ?


    My blog : http://thuruinhttp.wordpress.com
    Thursday, June 30, 2011 1:56 PM

Answers

All replies