資料庫使用 MS SQL Server 在 Entity Framework(EF)中如果要操作「like」查詢時,可以使用「Contains」,
例如以下的 LINQ Query:
var query = this.Products
.Where(x=>x.ProductName.Contains("CH"))
.OrderBy(x=>x.ProductID);
轉出的 SQL Command:
SELECT[Extent1].[ProductID] AS [ProductID],[Extent1].[ProductName] AS [ProductName],[Extent1].[SupplierID] AS [SupplierID],[Extent1].[CategoryID] AS [CategoryID],[Extent1].[QuantityPerUnit] AS [QuantityPerUnit],[Extent1].[UnitPrice] AS [UnitPrice],[Extent1].[UnitsInStock] AS [UnitsInStock],[Extent1].[UnitsOnOrder] AS [UnitsOnOrder],[Extent1].[ReorderLevel] AS [ReorderLevel],[Extent1].[Discontinued] AS [Discontinued]FROM [dbo].[Products] AS [Extent1]WHERE [Extent1].[ProductName] LIKE N'%CH%'ORDER BY [Extent1].[ProductID] ASC
而當資料庫使用 Oracle 時,LINQ Query 的操作還是使用「Contains」,但有些地方還是不同的。