Linq problem: The expression of type 'System.String[]' is not a sequence
I thought I would throw an omni-search on my data.
So I made a function that returns any match开发者_StackOverflow on a string.
ex.
var results = (from d in db.MyData
where new string[]{ d.DataField1.ToString(), d.DataField2.ToString(), ... }.Contains(searchTerm)
select d);
But when I try to iterate over it I get The expression of type 'System.String[]' is not a sequence.
//blows up on first iteration
foreach(var v in results)
{...}
Can anyone give me a few pointers?
Thanks!
I ran that query in Linqpad and it ran, but not how you wanted. It didn't do a LIKE against each field inside %'s, it did an IN against the set, which would only match if the data matched exactly. Can you just write it out?
var results = (from d in db.MyData
where d.DataField1.Contains(searchTerm) || d.DataField2.Contains(searchTerm)
select d);
精彩评论