开发者

Linq problem: The expression of type 'System.String[]' is not a sequence

开发者 https://www.devze.com 2023-01-16 08:13 出处:网络
I thought I would throw an omni-search on my data. So I made a function that returns any match开发者_StackOverflow on a string.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消