LINQ中,而不是在SQL是在、而不、LINQ、SQL

2023-09-07 01:29:24 作者:唯一的倾诉、

什么是不是等于的 LINQ到SQL ?

例如

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

什么是等于为SQL上述声明中的LINQ?

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

推荐答案

您使用,其中,<列表>。载(小于项目>)

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

或者你可以有一个列表predefined这样:

Or you can have a list predefined as such:

var ids = {1, 2, 3};

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

对于不的情况下,只需添加'!以前运营商的'包含'语句。

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