Wednesday, July 16, 2008

LINQ - .NET

LINQ stands for "Language Integrated QUery"
This really great feature can drastically ease SQL request.
Here is an example :

var products = from p in db.Products
where p.Category.Categoryname == "Beverages"
select p;

Here is the corresponding SQL statement :

SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], [t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]
FROM [dbo].[Products] AS [t0]
LEFT OUTER JOIN [dbo].[Categories] AS [t1] ON [t1].[CategoryID] = [t0].[CategoryID]
WHERE [t1].[CategoryName] = 'Beverages'

Choose your camp :-)

No comments:

Post a Comment