使用LINQ做一个具有多个值包含

编程入门 行业动态 更新时间:2024-10-07 12:22:47
本文介绍了使用LINQ做一个具有多个值包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有我在寻找某种药物名称的药物表,但我需要搜索多个名称。而这正是我目前它

的String [] =名新的字符串[2]; 名称[0] =阿哌沙班; 名称[1] =西卢; VAR吃药=(从药物m其中names.Any(m.BrandName.Contains)|| names.Any(m.GenericName.Contains)选择米);

我有什么不工作,我现在卡住了。我知道我很近,但我不能完全弄清楚什么是错的。

修改

有关澄清,如果我在寻找名字西卢,那么名优产品或通用名称会比较长,所以我必须有包含在数据库中的字段。

编辑2 这是我收到的错误。

用于查询经营者的任何不支持的超载。

下面是我终于结束了。

VAR吃药=(从db.AdmissionMedications m,其中(names.Any(N => m.BrandName.Contains(N))|| names.Any( N => m.GenericName.Contains(N)))选择米);

解决方案

也许财产以后像

VAR吃药=(从药物 m其中names.Any(名称=> name.Equals(m.BrandName)|| m.GenericName 。载有(名))选择M);

I have a medication table that I'm looking for certain drug names, but I need to search for multiple names. Here is where I currently am with it.

string[] names = new string[2]; names[0] = "apixaban"; names[1] = "desirudin"; var meds = (from m in Medications where names.Any(m.BrandName.Contains) || names.Any(m.GenericName.Contains) select m);

What I have isn't working, and I'm currently stuck. I know I'm close, but I can't quite figure out what's wrong.

EDIT

For clarification, if the name I'm searching for is desirudin, then the BrandName or Generic name will be longer, so I have to have the contains on the field in the database.

EDIT 2 Here is the error I recieve.

Unsupported overload used for query operator 'Any'.

Here is what I finally ended up with

var meds = (from m in db.AdmissionMedications where (names.Any(n => m.BrandName.Contains(n)) || names.Any(n => m.GenericName.Contains(n)) ) select m);

解决方案

Maybe somthing like

var meds = (from m in Medications where names.Any(name => name.Equals(m.BrandName) || m.GenericName.Contains(name)) select m);

更多推荐

使用LINQ做一个具有多个值包含

本文发布于:2023-11-26 23:07:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   做一个   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!