I have a custom DataContext with a Table member…
Entry is defined as…
[Table(Name="Entry")]
public class Entry
{
[Column]
public DateTime MyDate { get; set; }
}
The MyDate field in the Entry table can be NULL.
I have a very simple Linq query that retrieves all records in Entry but when it encounters a NULL MyDate field, I receive a System.InvalidOperationException error with the following details…
The null value cannot be assigned to a member with type System.DateTime which is a non-nullable value type.
Is there a way to set a default DateTime (with 0 ticks, for instance) when I encounter a NULL…?
Can you declare it as
public DateTime? MyDate { get; set; }?If you don’t want it to actually ever be null, you can do this:
This will give you 0 Ticks whenever the value in the DB is NULL.