I have a nullable int coming in from the database from a stored procedure that I know will not have a null value. I have done the bellow:
public List<EngineerDetails> GetCarouselEngineerDetailsList(int customerID)
{
using (var db = new MainEntities80())
{
var foo0= db.procedure().Select(s => new fooo()
{
foo= s.foo,
foo2 = s.foo2,
foo3 = s.foo3 ,
foo4 = s.foo4 ,
x = s.CurrentJobId.Value
}).ToList();
return foo0;
}
}
But I wanted to know although I know that the value will always be there. Is it good practice to check before getting the value. Maybe with a turnary expression. Or because we know it will not be null should we forget about the check?
An InvalidOperationException
will be thrown if s.CurrentJobId
is actually null anyway. That's almost always the best outcome for situations of "the world is not the way I expect it to be" so it makes sense to use the code exactly as-is.
See more on this question at Stackoverflow