MySQL, LINQ and The ADO NET Entity Framework
MySQL, LINQ and The ADO NET Entity Framework
command.Parameters.AddWithValue("?Country", country);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
results.Add(Customer.CreateFromReader(reader));
return results;
}
//Create aa query
//Create query for
for odd
odd numbers,
numbers sorted in descending order
var oddNumbers
var oddNumbers == from
from ii in
in myarray
myarray where i % 2 == 1 select i;
where i % 2 == 1
//Compose the original
select query
orderby i; to create a query for odd numbers
i descending
var sorted = fromselect
i in oddNumbers
i; orderby i descending select i;
Sweet spot:
• Strongly typed results, text-based queries
• Results returned as objects: entities / projections
• Queries more loosely defined at compile-time
Entity Framework Query Options
EntityClient Provider
string eSql = "SELECT VALUE o FROM NorthwindEntities.Orders AS o " +
"WHERE o.Customers.CustomerID = 'ALFKI'";
EntityCommand cmd = new EntityCommand(eSql, connectionString);
EntityDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
Console.WriteLine("{0} {1:d}", rdr["OrderID"], rdr["OrderDate"]);
Sweet spot:
• Untyped queries and results
• Results returned as DataReaders
• Queries can be generated purely at run time
No application model classes needed at compile time
Agenda
From DataSets to data access layers
Introducing LINQ
Using LINQ to access your data
The ADO.NET Entity Framework
Introducing ADO.NET Data Services
Summary
ADO.NET Data Services
Formerly known as "Project Astoria"
• Part of ASP.NET Extensions Preview
• Integrated into .NET Framework going forward
Targeting Web development technologies
• Silverlight and AJAX
• Data returned via Web-friendly formats
ATOM (XML-based) and JSON
ADO.NET Data Services
Service exposed via lightweight data access API
• Supply both location and query as a URI:
http://myserver/data.svc/Customers[ALFKI]/Orders
• Query converted to LINQ inside of service
• Supports submitting changes
Specialized Entity Framework logic for submitting changes
Online data hosting service available
For more information:
• http://astoria.mslivelabs.com
Agenda
From DataSets to data access layers
Introducing LINQ
Using LINQ to access your data
The ADO.NET Entity Framework
Introducing ADO.NET Data Services
Summary
Summary - LINQ
Represents a revolution for developers
• Query your objects using SQL-like syntax
• LINQ to DataSet
Rich query scenarios for data residing in a DataSet
• LINQ to Entities
Provider model for working with other data stores
Supports enterprise mapping scenarios
Summary - ADO.NET Entity Framework
More than just LINQ to Entities
• Also supports text-based query language – ESQL
• ObjectQuery<T> for strongly typed results
• EntityClient for reader-based results
Enterprise-grade data scenarios
Provider model for working with other data stores
Summary - ADO.NET Data Services
Designed for Silverlight, AJAX environments
Lightweight API, connect and query via URI
Retrieve results via familiar formats
• ATOM
• JSON
Questions?