I have a table that has Time1 and Time2 (for the sake of example). Time2 allows for nulls.
I have an object model and I want to have Time2 as nullable; so far I have this:
public Class MyModel{
public DateTime Time1 {get;set;}
public System.Nullable<DateTime> Time2 {get;set}
}
When I go to my query, I have this:
var MyQuery = ...
select new MyModel()
{
Time2 = (a.Time2)
and here I’m wondering if I should have the SingleOrDefault operator? It’s not showing in the intellisense. Howver, the intellisense is showing several other options, amongst whic are: HasValue, Value, GetValueOrDefault.
Any ideas on what’s the right one to choose from?
Thanks
That’s because Time2 is a nullable type. Nullable types always have a value property. If you revise your line to:
and then press the period symbol after Value, you’ll see the Intellisense pop up.
As a safety check you may want to also check that the value of a.Time2 is not null, before using .Value. Otherwise you’ll get a null reference exception