Reputation: 51917
I'm running a linq-to-sql query on a table that contains a nullable datetime like this:
var Output = from s in ....
select new MyModel()
{
TheCloseDate = s.TheCloseDate.DateTime.Value
}
However, the variable TheCloseDate
never gets filled. The MyModel definition of the variable is :
public Nullable<DateTime> TheCloseDate { get; set; }
What am I doing wrong here?
Thanks for your suggestions.
Upvotes: 3
Views: 494
Reputation: 29186
Try
var Output = from s in ....
select new MyModel()
{
TheCloseDate = s.TheCloseDate ?? null // Or whatever you want, like DateTime.Now
}
Upvotes: 4