简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM