开发者

Linq2SQL Filter on multi columns

开发者 https://www.devze.com 2023-04-08 23:12 出处:网络
If I have a data table like this id, Name, Address, Status How would I in Linq search across multiple columns?

If I have a data table like this

id, Name, Address, Status

How would I in Linq search across multiple columns?

So if I enter a search term of "slappy" I'd want all matches in columns Name, Address and Status开发者_如何学运维.

Is there an easy way or do I need to apply contains for each column?


var searchTerm = "slappy";
var result = context.table.Where(row => row.Name.Contains(searchTerm) ||
                                        row.Address.Contains(searchTerm) ||
                                        row.Status.Contains(searchTerm));


Did you consider to use a search engine library? It is not based on EF, but EF is not the best choice for your purpose. Surely you can mix technologies. http://incubator.apache.org/lucene.net/

0

精彩评论

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

关注公众号