Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Logica 2008. All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis

Similar presentations


Presentation on theme: "© Logica 2008. All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis"— Presentation transcript:

1 © Logica All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis

2 Microsoft en ORM – de historie WinFS

3 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

4 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

5 Taaluitbreidingen Extension methods Partial Methods Lambda expressions Anonymous types Object initializers Local variable inference Linq keywords and operators

6 Extention methods Local variable inference Anonymous types Demo

7 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());

8 IEnumerable

9 Ienumerable : enumeratie met yield return

10 Comprehension Syntax Demo

11 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( ));

12 LINQ to XML Demo

13 Data Access met LINQ LINQ to SQL

14 Object Relational Impedance Mismatch Objecten Objects != Data Relationele Data

15 Verschillen tussen LINQ to SQL en het Entity Framework

16 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

17 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

18 Linq to SQL : Mapping DB to Objects Database Table View Column Relationship Stored Procedure DataContext Class + Collection Property Nested Collection Method

19 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

20 LINQ to SQL No April 2015Title of Presentation Demo

21 Het ADO.Net Entity Framework Conceptual Mapping Logica l Object Model Relational Data Entity Table CSDL MSL SSDL Table

22 Entity Relationship Model Dr. Peter Chen, 1970

23 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

24 Lange termijn visie op data access

25 Resources Starten met Linq Linq ninjas LINQPad

26 Books


Download ppt "© Logica 2008. All rights reserved ADO vNext LINQ LINQ to SQL Entity Framework Freek Leemhuis"

Similar presentations


Ads by Google