It really bothers me. Here is a snippet of my model:
* SQL Server *
Event
-----
Id (int, PK) NOT NULL
Title (varchar(100)) NULL
LastModified (datetime) NULL
EventDates
----------
Id (int, PK) NOT NULL
StartDate (datetime) NULL
EndDate (datetime) NULL
* C
Event
-----
public int Id
public string Title
public DateTime LastModified
EventDates
----------
public int Id
public DateTime StartDate
public Datetime EndDate
The field LastModifiedhas been in the database since its creation. I save its value when I save an event, but I want to display it in a table, so I changed my Event GetEventsreturn repository
:return (from e in GetDbEvents()
select new Event
{
LastModified = e.LastModified.GetValueOrDefault()
});
When I call it, I scream:
The conversion of a char data type to a datetime data type
resulted in an out-of-range datetime value.
If I split the above code into this, it still won't help, and I get the same error if I try to list the result:
var test = (from e in _db.Events
select e.LastModified.GetValueOrDefault());
As a test, I made the same statement for my table EventDates(again, with two datetime columns):
var test4 = (from ed in _db.EventDates
select new EventDate
{
StartDate = ed.StartDate.GetValueOrDefault(),
EndDate = ed.EndDate.GetValueOrDefault()
});
This works great, of course. There are no errors when listing, all values are correct.
, LastModified Events NULL, EventDates .
- ? !
: Events , EventDates - , ?