如何在Linq中使用IN运算符? [英] How to use IN operator in Linq?

查看:81
本文介绍了如何在Linq中使用IN运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Select * from pu_Products 
    where Part_Number in ('031832','027861', '028020', '033378') 
    and User_Id = 50 and Is_Deleted = 0

上述查询是在SQL中进行的,我需要将查询转换为Linq.在Linq中可以使用"IN"运算符进行任何选择吗?您可以将上述查询转换为Linq吗?

The above mentioned query is in SQL and i need the query might be converted into Linq. Is there any option using the "IN" operator in Linq?. can you convert above mentioned query into Linq?

推荐答案

dbContext.Products
    .Where(p => (new string[] {"031832","027861","028020","033378"})
        .Contains(p.Part_Number) && p.Is_Deleted == false);

这篇关于如何在Linq中使用IN运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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