LINQ, "Value cannot be null", yet query evaluates
I have the following linq query:
var test = vendorContact.vendorContactItem
.Where(x => x.ItemNumber == vendo开发者_运维百科rContactItem.Item_Number)
.FirstOrDefault();
It fails on this piece of code, "Value cannot be null, parameter name: source" ... yet it also displays, in the local variables window, "test" as a variable with all its properties populated.
vendorContact.VendorContactItem
is null. Presumably this would be the first element to be added to the list. So how is "test" evaluating correctly while simultaneously throwing up that error?
I'm new to Linq, so excuse me if this is an obvious question.
If this is in a loop test
in the locals window contains the last value of test
, from the last iteration of the loop.
Edit: This has really nothing to do with LINQ, but how the debugger works.
精彩评论