LINQ to SQL in 和 not in [英] LINQ to SQL in and not in

查看:30
本文介绍了LINQ to SQL in 和 not in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 innot in 等于 LINQ to SQL?

What is in and not in equals in LINQ to SQL?

例如

select * from table in ( ...)
and 
select * from table not in (..)

LINQ to SQL 中的上述语句等于什么?

What is equal to the above statement in LINQ to SQL?

推荐答案

你使用,where <list>.Contains( <item> )

var myProducts = from p in db.Products
                 where productList.Contains(p.ProductID)
                 select p;

或者你可以预先定义一个列表:

Or you can have a list predefined as such:

int[] ids = {1, 2, 3};

var query = from item in context.items
            where ids.Contains( item.id )
            select item;

对于NOT"情况,只需添加!"'Contains' 语句之前的运算符.

For the 'NOT' case, just add the '!' operator before the 'Contains' statement.

这篇关于LINQ to SQL in 和 not in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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