How do I identify that a record is a result or a Default?
-
when executing the following code:
SomeObject myObject = context.Table.SelectSingleOrDefault();
How can I easily determin that the value of myObject has been set to default instead of a value? Thanks
-
when executing the following code:
SomeObject myObject = context.Table.SelectSingleOrDefault();
How can I easily determin that the value of myObject has been set to default instead of a value? Thanks
Check if
myObject == default(SomeObject)
. Obviously, if the there is a single result whose value is the default falue (e.g. 0 if SomeObject is an int), you can't tell apart form the case when there is no value and the default is returned. You can always checkcontext.Table.Count() != 0
to see if there are values, or usecontext.Table.Single()
and handle the exception if there are no values.