问题
I have a problem in a Linq-Where method. I get a NullReferenceException in a where clause, which should not happen because C# should use short-circuiting and the second operations hould not be executed:

If Item
is null, Item.State == ...
should not be called, because the condition is already true (short-circuiting).
But it seems, that short-circuiting does not working in this case.
Does anyone else had and solved this problem? Thank you!
Edit:
In the end, the connectionList
should not contains any null-values and no broken connections.
回答1:
This is common problem, when querying against databases. Namely, translating short-circuiting behavior against databases, don't work the way as you would expect. You can read more about such behavior: The || (or) Operator in Linq with C#
You could try this:
connectionList.RemoveRange(connectionList.Where(x => x==null));
connectionList.SaveChanges();
connectionList.RemoveRange(connectionList.Where(x => x.Item==BrokenState));
just to see if it works.
来源:https://stackoverflow.com/questions/27900005/short-circuiting-in-linq-where