开发者

Linq2SQL Filter on multi 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜