I'm writing a linq-to-sql query and I'm loading an ID (a bigint
in the database and a long
in my code) from a table, something like this:
var SomeQuery = (from x in ...
select x.ID).SingleOrDefault();
When I get the result, I use SingleOrDefault
in case the return is empty. Does that mean that if the result is empty the SomeQuery
variable will be 0 or null?
Thanks.
Default is returned if no element found.(default value of int is 0)
Value is returned if one is found.
Exception is thrown if more than one is found.
If you look the documenation for SingleOrDefault
It cleary states that if the sequence is empty it will return the default value which for long and bigint is 0. Why explained below
Documenation for default keyword states