English 中文(简体)
“IN”关键词的LINQ当量
原标题:What is LINQ equivalent of SQL’s "IN" keyword

我如何在林克的 s下书写字

select * from Product where ProductTypePartyID IN
(
    select Id from ProductTypeParty where PartyId = 34
)
最佳回答

除语气差异外,你实际上可以这样写。

from p in ctx.Product
where (from ptp in ctx.ProductTypeParty
       where ptp.PartyId == 34
       select ptp.Id).Contains(p.ProductTypePartyID)
select p

我更喜欢使用现有标准,但:

from p in ctx.Product
where (from ptp in ctx.ProductTypeParty
       where ptp.PartyId == 34
       && ptp.Id == p.ProductTypePartyID).Any()
select p

我预计,这一表格将决心在制作的SQ中采用EXISTS(SlectT * >

如果业绩有巨大差异,你就希望说明两者。

问题回答

There is no direct equivalent in LINQ. Instead you can use contains () or any other trick to implement them. Here s an example that uses Contains:

String [] s = new String [5];
s [0] = "34";
s [1] = "12";
s [2] = "55";
s [3] = "4";
s [4] = "61";

var  result = from d in  context.TableName
              where s.Contains (d.fieldname)
              select d;

详细检查这一联系:in article Linq

int[] productList = new int[] { 1, 2, 3, 4 };


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

与此类似

var partyProducts = from p in dbo.Product 
                    join pt in dbo.ProductTypeParty on p.ProductTypePartyID equal pt.PartyId 
                    where pt.PartyId = 34 
                    select p

您在条款中使用该术语。

根据这些路线(未测试):

var results = Product.Where(product => ProductTypeParty
                                            .Where(ptp => ptp.PartyId == 34)
                                            .Select(ptp => ptp.Id)
                                            .Contains(product.Id)
                           );




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签