VB.NET LINQ query on List(Of Object) -


i having trouble linq query -

 dim otherrecords list(of objects) = listof.where(function(x) x.id_num = newid _                                         , (x.codes.contains(ddlprimarycode.selecteditem.text.trim) , not x.codes = nothing)).tolist() 

error exception of type 'system.nullreferenceexception' occurred in ci.dll not handled in user code

additional information: object reference not set instance of object.

the problem listof contains value "nothing" x.codes.contains.

before had

 dim otherrecords list(of objects) = listof.where(function(x) x.id_num = newid _                                                        , (x.codes.contains(ddlprimarycode.selecteditem.text.trim)).tolist()   

and crapping out.

i need able return records matching id_num , codes.

you need check if it's nothing first , use andalso keyword stop evaluating latter statement. andalso short-circuiting. see this link more information on means.

also, when checking if object null, should use is or isnot operator rather =. this msdn article:

when checking whether reference (or nullable value type) variable null, not use = nothing or <> nothing. use nothing or isnot nothing.

this should work

dim otherrecords list(of objects) = listof.where(function(x) _                                                         (x.id_num = newid) andalso _                                                         (x.codes isnot nothing) andalso _                                                         (x.codes.contains(ddlprimarycode.selecteditem.text.trim()))).tolist() 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -