c# - vb.net linq where clause for mutiple search filter - same query but different where clause -


i know question answered in c# when try covert online c# vb.net got running errors.

disclaimer not code

   string personname = txtpersonname.text;    int personage = convert.toint32(txtage.text);    var opportunites =  p in this.datacontext.persons                         select new                         {                             p.personid,                             p.name,                             p.age,                             p.gender                         };      if (personsid != 0)         opportunites = opportunites.where(p => p.personid == personid);      if (personname != string.empty)         opportunites = opportunites.where(p => p.name.startswith(personname));      if (personage != 0)         opportunites = opportunites.where(p => p.age == personage); 

can me convert code think c#, can can't convert vb.net tried telerik no luck.

i can't call/use 'p' in linq select new {} on if statement.

there 2 areas seem having problems with: anonymous type , lambdas - conversion below should clarify these issues: option infer on

dim personname string = txtpersonname.text dim personage integer = convert.toint32(txtage.text) dim opportunites = p in me.datacontext.persons     select new {         key p.personid,         key p.name,         key p.age,         key p.gender     }  if personsid <> 0     opportunites = opportunites.where(function(p) p.personid = personid) end if  if personname <> string.empty     opportunites = opportunites.where(function(p) p.name.startswith(personname)) end if  if personage <> 0     opportunites = opportunites.where(function(p) p.age = personage) end if 

Comments