© Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis
Microsoft en ORM – de historie WinFS
Defining LINQ and LINQ to SQL Bestaat uit taal uitbreidingen in C# 3.0 en VB 9.0 Uniforme manier om queries uit te voeren op objecten Een framework (OR mapper) voor het mappen van data classes op SQL Server tables, views en stored procedures. LINQ to SQL LINQ
LINQ parts C# 3.0C# 3.0 VB 9.0VB 9.0 OthersOthers LINQLINQ Interne query engine LINQ to Objects.Net APIs LINQ to Datasets LINQ to XML Providers LINQ to SQL LINQ to Entities IQueryableIEnumerable
Taaluitbreidingen Extension methods Partial Methods Lambda expressions Anonymous types Object initializers Local variable inference Linq keywords and operators
Extention methods Local variable inference Anonymous types Demo
De basis van LINQ LINQ queries gaan over elementen uit sequences Een sequence is een object dat de IEnumerable interface implementeert Bijvoorbeeld: String[] namen = {“Maarten”, “Ralph”, “Freek”}; Selectie = namen.Where(n=>n.Contains(“a”)).Orderby(n=>n).Select(n=>n.ToUpper());
IEnumerable
Ienumerable : enumeratie met yield return
Comprehension Syntax Demo
Query voorbeelden Query composition var filtered = names.Where (n => n.Contains ("a")); var sorted = filtered.OrderBy (n => n); var query = sorted.Select (n => n.ToUpper( ));
LINQ to XML Demo
Data Access met LINQ LINQ to SQL
Object Relational Impedance Mismatch Objecten Objects != Data Relationele Data
Verschillen tussen LINQ to SQL en het Entity Framework
Data Access met ADO.Net SqlConnection c = new SqlConnection(…); c.Open(); SqlCommand cmd = new c.Name, c.Name, c.Phone FROM Customers c FROM Customers c WHERE c.City WHERE c.City "London“); DataReader dr = c.Execute(cmd); while (dr.Read()) { string name = dr.GetString(0); string name = dr.GetString(0); string phone = dr.GetString(1); string phone = dr.GetString(1); DateTime date = dr.GetDateTime(2); DateTime date = dr.GetDateTime(2);}dr.Close(); Data Access met klassiek ADO.Net Queries in quotes Loosely bound arguments Loosely typed result sets No compile time checks
public class Customer { … } public class Northwind: DataContext { public Table Customers; public Table Customers; …} Northwind db = new Northwind(…); var contacts = from c in db.Customers from c in db.Customers where c.City == "London" where c.City == "London" select new { c.Name, c.Phone }; select new { c.Name, c.Phone }; Data Access met LINQ to SQL Classes describe data Strongly typed connection Integrated query syntax Strongly typed results Tables are like collections
Linq to SQL : Mapping DB to Objects Database Table View Column Relationship Stored Procedure DataContext Class + Collection Property Nested Collection Method
LINQ to SQL Architectuur from c in Context.Customers Where c.LastName. StartsWith(“Niks”) select new { c.Name, c.FirstName}; from c in Context.Customers Where c.LastName. StartsWith(“Niks”) select new { c.Name, c.FirstName}; select Name, FirstName from customers where Lastname like ‘Niks%' LINQ to SQL DataContext SQL Server Customer c = new Customer(); Customer.LastName = “Bos”; Customers.InsertOnSumbit(c); Context.SubmitChanges(); Dynamische SQL of Stored Procedure ApplicatieApplicatie Services: - Change tracking - Concurrency control - Object identity
LINQ to SQL No April 2015Title of Presentation Demo
Het ADO.Net Entity Framework Conceptual Mapping Logica l Object Model Relational Data Entity Table CSDL MSL SSDL Table
Entity Relationship Model Dr. Peter Chen, 1970
Entity Framework Layers Conceptual Mapping Logical Entity Framework Architecture CSDL Entity SQL MSL SSDL Entity Client Entity SQL Object Services Object Query LINQ to Entities
Lange termijn visie op data access
Resources Starten met Linq Linq ninjas LINQPad
Books