LINQ C#数据集搜索问题 [英] LINQ C# Dataset search problem

查看:87
本文介绍了LINQ C#数据集搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的参数.SearchText是一个List< string>包含搜索词.似乎此代码返回的数据行包含列表中的任何字符串.我希望它仅返回包含列表中所有字符串的数据行.有想法吗?


My parameters.SearchText is a List<string> containing search words. It seems this code returns a datarow that contains any string in the list. I want it to return only the datarows that contain ALL of strings in the list. Thoughts?


var query1 =
         from nodes in Datasets.Datasets.dsQuestions.Tables["key"]
         from _searchtext in parameters.SearchText
             where 
             nodes.Field<string>("Question").ToUpper().Contains(_searchtext.ToUpper())                         
         select nodes;




更新:由于不需要关键字,因此我删除了搜索关键字的行.




Update: I took out the line to search Keywords since it was irrelevant.

推荐答案

使用&&代替|| ..
它将成为
Use && instead of ||..
So it will become
var query1 =
    from nodes in Datasets.Datasets.dsQuestions.Tables["key"]
    from _searchtext in parameters.SearchText
    where
        nodes.Field<<string>("Question").ToUpper().Contains(_searchtext.ToUpper())
        &&
        nodes.Field<string>("Keyword").ToUpper().Contains(_searchtext.ToUpper())
    select nodes;


var query1 = Datasets.Datasets.dsQuestions.Tables["key"].Select(k=> parameters.SearchText.All(x => k.Field<string>("Question").ToUpper().Contains(x.ToUpper())
		 || k.Field<string>("Keyword").ToUpper().Contains(x.ToUpper())));


var query1 = Datasets.Datasets.dsQuestions.Tables ["key"].Rows.OfType< datarow>().Where(k => ; parameters.SearchText.All(x => k.Field< string>(问题").ToUpper().包含(x.ToUpper())));


感谢达米思(Damith)向我指出了正确的方向.
var query1 = Datasets.Datasets.dsQuestions.Tables["key"].Rows.OfType<datarow>().Where(k => parameters.SearchText.All(x => k.Field<string>("Question").ToUpper().Contains(x.ToUpper())));


Thanks to Damith for pointing me in the right direction.


这篇关于LINQ C#数据集搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆