如何在linq查询中使用contains? [英] How to use contain in linq query?
问题描述
我希望能够查询(name)参数,例如(api / data?name = prestl,accam,bcam ...(25个值)。这是我现在拥有的并且代码抛弃了我以下问题:
委托'System.Func< Testing_Apr.database_Bd,int,bool>'不带1个参数
字符串'不包含'split'的定义,也没有扩展方法'split'接受类型'的第一个参数可以找到字符串'(你是否错过了使用指令或汇编引用?)
I would like to be able to query the (name) parameter such as (api/data?name=prestl,accam,bcam...(25 values). This is currently what I have and the code is throwing me the following issues:
Delegate 'System.Func<Testing_Apr.database_Bd,int,bool>' does not take 1 arguments
string' does not contain a definition for 'split' and no extension method 'split' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
var data = db.database_Bd.AsQueryable();
if (query.startDate != null)
{
data = data.Where(c => c.UploadDate >= query.startDate);
}
if (!string.IsNullOrEmpty(query.name))
{
var list = query.name.split(',');
data = data.Where(pr => list.Any(pr2 => pr.Name.Contains(pr2)));
}
任何建议都非常感谢。
非常感谢
Any advice, would be very much appreciated.
Many thanks
推荐答案
C#区分大小写:split与Split不一样
尝试:
C# is case sensitive: "split" is not the same as "Split"
Try:
var list = query.name.Split(',');
这篇关于如何在linq查询中使用contains?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!