1. Query all fields
using New Northwindcontext ()) { var expr = context. Products; foreach (var in expr) { Console.WriteLine (item. ProductName);} }
SELECT [Extent1].[ProductID] as [ProductID], [Extent1].[CategoryID] as [CategoryID], [Extent1].[ProductName] as [ProductName], [Extent1].[UnitPrice] as [UnitPrice], [Extent1].[discontinued] as [discontinued] from [dbo].[Product] as [Extent1]
2. Querying a specified field
var expr = context. Products new {p.productid, p.productname});
SELECT [Extent1].[ProductID] as [ProductID], [Extent1].[ProductName] as [ProductName] from [dbo].[Product] as [Extent1]
3. First/firstordefault
var expr = context. Products.first ();
SELECT TOP(1) [C].[ProductID] as [ProductID], [C].[CategoryID] as [CategoryID], [C].[ProductName] as [ProductName], [C].[UnitPrice] as [UnitPrice], [C].[discontinued] as [discontinued] from [dbo].[Product] as [C]
LINQ series: LINQ to SQL Select query