I am trying to search within a string for a specific value.
What I want to do is SPLIT the string and look at each value.
If the mySearch.EQUALS(split-string-value) then return the record(s) in a ToList().
This is my code.. It returns ZERO RECORDS
// user search for sku = "2012"
// p.productMatch in DB = "2012,2012L,2012LR,2011"
var result = ctx.Products
.Where(p => p.clientID == Config.ClientID)
.Where(p => p.productMatch.Contains(sku))
.Select(v => new ProductView
{
productID = v.productID,
productMatch = v.productMatch,
productSKU = v.productSKU
}).ToList();
var results = from w in result
where w.productMatch.Split(',').Equals(sku)
select w;
return results.ToList();
At the moment, in your
where w.productMatch.Split(',').Equals(sku)line you compare result ofSplit()(which is array of strings) with single stringsku. For obvious reasons this fails. Simply change it to: