LINQ 시리즈: LINQ to SQL Exists / In / Any / All / Contains
21333 단어 contains
제품 이 없 는 카 테 고리 되 돌리 기
var expr = from c in context.Categories
where !c.Products.Any()
select c;
SELECT
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[CategoryName] AS [CategoryName]
FROM [dbo].[Category] AS [Extent1]
WHERE NOT EXISTS (SELECT
1 AS [C1]
FROM [dbo].[Product] AS [Extent2]
WHERE [Extent1].[CategoryID] = [Extent2].[CategoryID]
)
var expr = from c in context.Categories
where !c.Products.Any(p => p.UnitPrice > 10m)
select c;
SELECT
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[CategoryName] AS [CategoryName]
FROM [dbo].[Category] AS [Extent1]
WHERE NOT EXISTS (SELECT
1 AS [C1]
FROM [dbo].[Product] AS [Extent2]
WHERE ([Extent1].[CategoryID] = [Extent2].[CategoryID]) AND ([Extent2].[UnitPrice] > cast(10 as decimal(18)))
)
2. All
var expr = from c in context.Categories
where c.Products.All(p => p.Discontinued)
select c;
SELECT
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[CategoryName] AS [CategoryName]
FROM [dbo].[Category] AS [Extent1]
WHERE NOT EXISTS (SELECT
1 AS [C1]
FROM [dbo].[Product] AS [Extent2]
WHERE ([Extent1].[CategoryID] = [Extent2].[CategoryID]) AND ([Extent2].[Discontinued] <> cast(1 as bit))
)
3. Contains
var expr = from p in context.Products
where new string[]
{
"LINQ to Object",
"LINQ to ADO.NET",
"LINQ to XML"
}
.Contains(p.ProductName)
select p;
SELECT
[Extent1].[ProductID] AS [ProductID],
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[ProductName] AS [ProductName],
[Extent1].[UnitPrice] AS [UnitPrice],
[Extent1].[UnitsInStock] AS [UnitsInStock],
[Extent1].[Discontinued] AS [Discontinued]
FROM [dbo].[Product] AS [Extent1]
WHERE [Extent1].[ProductName] IN (N'LINQ to Object', N'LINQ to ADO.NET', N'LINQ to XML')
var expr = from p in context.Products
where !(new string[]
{
"LINQ to Object",
"LINQ to ADO.NET",
"LINQ to XML"
})
.Contains(p.ProductName)
select p;
SELECT
[Extent1].[ProductID] AS [ProductID],
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[ProductName] AS [ProductName],
[Extent1].[UnitPrice] AS [UnitPrice],
[Extent1].[UnitsInStock] AS [UnitsInStock],
[Extent1].[Discontinued] AS [Discontinued]
FROM [dbo].[Product] AS [Extent1]
WHERE NOT ([Extent1].[ProductName] IN (N'LINQ to Object', N'LINQ to ADO.NET', N'LINQ to XML'))
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
최신 Contains () 메서드 작성텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.