Why does 'Submissions.Where (s => (false && s.Status == Convert.ToInt16 ("")))' raise a FormatException?

I thought the query was pretty trivial, but at the same time raising the exception format ("The input string was not in the correct format"):

Submissions.Where(s => (false && s.Status == Convert.ToInt16("")))

(of course, in my code another expression that evaluates to "false" is located before "& &")

So why is the role after && evaluated, since the first part is always false and the full expression can never evaluate the value true?

The situation is especially strange, because only a part Convert.ToInt16("")seems to throw an exception - other parts of my original request are more or less of the same structure, for example

Submissions.Where(s => (false && s.SubmissionDate <= DateTime.Now))

evaluated correctly.

+3
4

, LINQ to SQL , SQL . SQL #, , SQL .

MSDN:

# && ||. SQL , , .

, , Convert.ToInt16("") , . , .

+6

Submissions IQueryable<T>, #, . ( LINQ) - , , .

+5

, , Linq to Sql, . Linq , , , . .. , " ". Linq to Sql, , , .

+2

Suggestion: use static Int16 to store the result of Convert.ToInt16 (""), then refer to the static in the predicate.

Better yet, do you know what the result of Convert.ToInt16 ("") is? Yes? Then use it instead. For example, if it is 0, say s.Status == 0. You can even make it a constant.

0
source

Source: https://habr.com/ru/post/1710572/


All Articles