在一列中搜索多个值 [英] Search multiple values in one column

查看:54
本文介绍了在一列中搜索多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用linq查询在一列中基于多个值搜索来选择记录. 像产品ID是"product1","product2","product3",我们拥有n个值

How to select record based on multiple values search in one column using linq query. like product id is "product1", "product2","product3" n number of values we have

推荐答案

您可以使用.Contains方法检查值是否在列表中.

You can use the .Contains method to check whether a value is within a list.

var values = new List<string>() { "Prod1", "Prod2", "Prod3" };
var query = context.Set<Product>().Where(x => values.Contains(x.Name));

这篇关于在一列中搜索多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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