linq query where int ID belongs to List<int>

c#, linq, list

Solution

You can use the null-coalescing operator here:

var rTestResults = from rT in mDataContext.TestSamplesViews 
               where rMTCPlates.Contains(rT.PlateID ?? 0) 
               select rT; 

Problem

I'm having a problem with a linq query. I have used this similarly before but i cannot understand what could be wrong now. Errors The best overloaded method match for 'System.Collections.Generic.List.Contains(int)' has some invalid arguments Argument '1': cannot convert from 'int?' to 'int' ; refers to the where clause of rTestResults Code: ``` List<int> rMTCPlates = (from rP in mDataContext.Plates where rP.SOItem.SONumberID == aSONumber select rP.ID).ToList(); var rTestResults = from rT in mDataContext.TestSamplesViews where rMTCPlates.Contains(rT.PlateID) select rT; ``` Any idea whats going on? Any help appreciated, Thanks

Original source

Related problems