从单个文本框中搜索单个和多个关键字 [英] Search by single and multiple key words both from single textbox
本文介绍了从单个文本框中搜索单个和多个关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过上面的代码,我可以获得多个关键字的详细信息,但同时,我也希望通过单个关键字获取记录。
请帮助我一些人,提前致谢
我的尝试:
By Above code I can get details for multiple keywords but at the same time, I want to get records by single keyword also.
Please some one help me, Thanks in Advance
What I have tried:
var db = new MatriModel();
string s = txtKeyWord.Text;
string[] words = s.Split(',');
int count = words.Length;
if (count <= 5))
{
SerachByKeyWordPanel.Visible = true;
var KeyWord = db.tblProfiles.Where(x => words.Contains(x.tblCaste.Caste) && words.Contains(x.tblCountry.Country) && words.Contains(x.City) && words.Contains(x.tblOccupation.Occupation) && words.Contains(x.tblMotherTongue.MotherTongue)).Select(x => new
{
ProfileID = x.ProfileID,
ProfileFor = x.tblProfileFor.ProfileFor,
}.ToList();
推荐答案
与在哪里
你必须使用任何 [ ^ ] Linq方法;)
查看我过去对问题的回答:使用LINQ的1个参数中的多个值 [ ^ ]
我的最佳猜测:
Together withWhere
you have to use Any[^] Linq method ;)
Check my past answer to the question: Multiple values in 1 parameter using LINQ[^]
My best guess:
var KeyWord = db.tblProfiles
.Where(x => words.Any(y=< y==x.tblCaste.Caste) ||
words.Any(y=< y==x.tblCountry.Country) ||
words.Any(y=< y==x.City) ||
words.Any(y=< y==x.tblOccupation.Occupation) ||
words.Any(y=< y==x.tblMotherTongue.MotherTongue))
.Select(...);
注意:未对大部分数据进行测试。
Note: not tested on large portion of data.
这篇关于从单个文本框中搜索单个和多个关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文