Introducing the object context, basics queries, eager loading, lazy loading and projection.
In this video, Julie Lerman will show you how to query your database with LINQ to Entities queries against an Entity Data Model. This video uses Entity Framework 4.0 and Visual Studio 2010.
Presented by Julie Lerman.
Presented by Julie Lerman.
Context object
var context = new myModel.MyEntities
Basic query
var query = from c in context.Customers select c;
var customers = query.ToList();
Basic filter query
var query = from c in context.Customers where c.customerID==5 select c;
var customer = query.FirstOrDefault();
Eager loading
var query = from c in context.Customers.Include("SalesOrdersHeaders") where c.customerID==5 select c;
var customer = query.FirstOrDefault();
Lazy loading (.NET 4 only)
var query = from c in context.Customers where c.customerID==5 select c;
var customer = query.FirstOrDefault();
lblTest.Text = customer.SalesOrdersHeader.Count
Projection
var query = from c in context.Customers where c.customerID==5
select new { c.CustomerID, c.Firstname, c.Lastname };