1 / 52

LINQ i alla dess smaker

LINQ i alla dess smaker. Johan Lindfors blogs.msdn.com/johanl Johan.Lindfors@microsoft.com. Patrik Löwendahl www.lovendahl.net Patrik.Lowendahl@cornerstone.se. Bakgrund och utmaningar. Message Object. Domain Model. XML. Data Transfer Object. Active Record. DataTable. DataSet.

Download Presentation

LINQ i alla dess smaker

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LINQ i alla dess smaker Johan Lindfors blogs.msdn.com/johanlJohan.Lindfors@microsoft.com Patrik Löwendahl www.lovendahl.netPatrik.Lowendahl@cornerstone.se

  2. Bakgrund och utmaningar

  3. Message Object Domain Model XML Data Transfer Object Active Record DataTable DataSet Objekts modell Repositories DataReader

  4. !

  5. ADO.NET

  6. DataSet DataTable DataTable

  7. SQL Server 2005 SQL Server 6.5 Categories Products Customers Orders SqlDataAdapter OleDbDataAdapter DataSet Categories Products Employees Customers Orders XmlDataDocument XML Fil Web service

  8. För- och nackdelar

  9. Domänmodeller

  10. Fokus på applikation inte lagring Frikopplar affärslogik från datastrukturen Större möjligheter till återanvändning och utökningar

  11. För- och nackdelar

  12. LINQ

  13. LINQ-projektet <book> <title/> <author/> <year/> <price/> </book> Relationer Objekt XML .NET Language Integrated Query C# 3.0 Visual Basic 9.0 Andra… LINQ toObjects LINQ toDataSets LINQ toSQL LINQ toEntities LINQ toXML

  14. Nyheter i C# 3.0 “Query expressions” var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; “Local variable type inference” “Lambda expressions” var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); “Extension methods” “Anonymous types” “Object initializers”

  15. LINQ to SQL

  16. Designmål Direkt mappning mot SQL RAD ”Deferred Execution” Mål: Microsoft SQL Server RTM: Visual Studio 2008

  17. Anpassning av affärslogiken Partiella klasser och metoder Lagrade procedurer Optimering Kompilerade frågor

  18. LINQ to Entity Framework

  19. Koncept vi skall beröra Mappning Att ställa frågor Updatera data Stored procedures Arkitektur

  20. Mappning

  21. Källa: www.endintiers.com

  22. Conceptual Model Map Storage/Logical Model Entity Data Model Schema Datastore Objects Schema *.CSDL *.MSL *.SSDL Datastorage OO Classes

  23. Att ställa frågor

  24. ObjectQuery<T> ObjectContext EntityDataReader EntityCommand EntityConnection EntityDataReader EntityCommand EntityConnection Database

  25. EF Stored Procs & TVFs Entity SQL Queries Normalised Application Objects Views Database LINQ to Entities Queries ‘Optimised’ Dynamic SQL

  26. LazyLoad Källa: www.martinfowler.com

  27. Load spans

  28. Identitymap Källa: www.martinfowler.com

  29. Uppdatera data

  30. ObjectContext UnitOfWork

  31. Stored procedures

  32. Functionmapping SSDL: <Function Name="TenMostExpensiveProducts" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false” ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" /> CSDL: <FunctionImport Name="TenMostExpensiveProducts" EntitySet="Products" ReturnType="Collection(NorthwindEFModel.Products)" /> MDL: <FunctionImportMapping FunctionImportName="TenMostExpensiveProducts” FunctionName="NorthwindEFModel.Store.TenMostExpensiveProducts"/> Context: var query = context.TenMostExpensiveProducts();

  33. Insert / Update / Delete SSDL: <Function Name="CreateCategory" IsComposable="false”> <Parameter Name="CategoryName" Type="nvarchar" /> </Function> <Function Name="EditCategory" IsComposable="false"> <Parameter Name="CategoryID" Type="int" /> <Parameter Name="CategoryName" Type="nvarchar" /> </Function> <Function Name="RemoveCategory" IsComposable="false"> <Parameter Name="CategoryID" Type="int" /> </Function> MDL: <ModificationFunctionMapping> <InsertFunction FunctionName="dbo.CreateCategory”> <ScalarProperty Name="CategoryName” parameterName="CategoryName" /> <ResultBinding ColumnName="CategoryID" Name="CategoryID"/> </InsertFunction> <UpdateFunction FunctionName="dbo.EditCategory”> <ScalarProperty Name="CategoryID” ParameterName="CategoryID” Version="current"/> <ScalarProperty Name="CategoryName” ParameterName="CategoryName” Version="current"/> </UpdateFunction> <DeleteFunction FunctionName="dbo.RemoveCategory”> <ScalarProperty Name="CategoryID” ParameterName="CategoryID"/> </DeleteFunction> </ModificationFunctionMapping>

  34. Arkitektur

  35. SQL Server Relational DBMS Applications Programming Layers Code Gen • XML • XLinq • XQuery • Objects • Linq … Browsing Binding Entity Client – EDM, Entity SQL Domain Modeling Tools Metadata Services Query and Update Pipelines Mapping Mapping Entity Framework Runtime Transactions Modeling Data Providers (ADO.NET patterns) SqlClient OtherClient Non-relational Web Service

  36. Läs mer… http://forums.msdn.com http://msdn.microsoft.com/data http://www.lowendahl.net http://blogs.msdn.com/adonet http://forum.cornerstone.se http://blogs.msdn.com/angelsb

  37. LINQ to DataSet

  38. ”Disconnected cache” Otypade var query = from row in myDataSet.Tables["Customers"].AsEnumerable() where row .Field<string>("City") == "London" select new { row.Field <string> ("CustomerID"), row.Field <string> ("ContactName") } ; Typade var query = from customer in northwind.Customers where customer.City == "London" select customer;

  39. LINQ to XML

  40. ”Astoria”

More Related