I am trying to run the below code, and it works properly until I try and add a second search value after using a comma to add a new value that gets added to the array of values. In SQL terms, I basically want to add the "AND" keyword after each loop iteration. Is this somehow possible?
var query = from s in db.Items
join c in db.Categories on s.Category equals c.ID into cats from c in cats.DefaultIfEmpty()
join ma in db.Makes on s.Make equals ma.ID into maks from ma in maks.DefaultIfEmpty()
join mo in db.Models on s.Model equals mo.ID into mods from mo in mods.DefaultIfEmpty()
join st in db.Status on s.Usage_Status equals st.ID into stats from st in stats.DefaultIfEmpty()
join d in db.Departments on s.Department equals d.ID into deps from d in deps.DefaultIfEmpty()
select new { item = s, cat = c, make = ma, model = mo, status = st, department = d };
if (!String.IsNullOrEmpty(searchString))
{
string[] searchValues = searchString.Split(',');
for (var x = 0; x < searchValues.Length; x++)
{
var value = searchValues[x];
query = query.Where(s => s.item.Asset_Tag_Nbr.Contains(value)
|| s.item.Serial.Contains(value)
|| s.cat.Name.Contains(value)
|| s.make.Name.Contains(value)
|| s.model.Name.Contains(value)
|| s.item.Assigned_User.Contains(value));
}
}
This, That, you want to get the items where one of the properties contains bothThisandThat? are you sure you wantandand notor? BTW,searchValues[x]is already a string, theToStringis redundant.