1 / 14

LINQ to Relational Data

LINQ to Relational Data. Michael Pizzo Software Architect Data Programmability Microsoft Corporation. Agenda. LINQ to Relational LINQ to SQL LINQ to Entities LINQ to DataSet Summary. LINQ to SQL Strongly typed SQL Database. Design Points Rapid Development against SQL Database

cynara
Download Presentation

LINQ to Relational Data

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 to Relational Data Michael Pizzo Software Architect Data Programmability Microsoft Corporation

  2. Agenda • LINQ to Relational • LINQ to SQL • LINQ to Entities • LINQ to DataSet • Summary

  3. LINQ to SQLStrongly typed SQL Database • Design Points • Rapid Development against SQL Database • Direct Mapping to SQL Server Schema • Mappings expressed in Attributes or XML file • "Just Work" for common scenarios • Execute when needed • Naming Conventions • Business Logic • Custom Insert/Update/Delete operations • Minimally Intrusive object model • Provide Customization, Optimizations where required • Targets: Microsoft SQL Server • RTM: Microsoft Visual Studio 2008 RTM

  4. LINQ to SQLDirect Mapping • Direct Mapping • Each class maps to a single SQL Schema Object • Table, View • Stored Procedure, Table Valued Function • Simple renaming of Tables, Columns • Foreign Keys can be expressed as Relationships • Properties to navigate in query, results • Inheritance • Multiple Classes in a Hierarchy can map to a single Table/View/Stored Proc/TVF with a discriminator column

  5. LINQ to SQLFeatures • Customization • Business Logic • Partial classes for generated Objects • Add Methods, non-persistent members, etc. • Business Logic through Partial methods based on naming conventions • Update Logic • Implement partial methods in derived Class • Call Stored Procedures or invoke custom logic • Optimizations • Loading Options • "Span" related information • ObjectTrackingEnabled • DeferredLoadingEnabled • Compiled Query • Save overhead of SQL generation from Language Expression

  6. Direct Mapping with LINQ to SQL

  7. LINQ to EntitiesFlexible Mapping to Relational Data • Design Points • Flexible Mapping to Existing Relational Schema • Well defined Conceptual model • Share common model across products (Reporting, Analysis, etc…) • Declarative Mapping between Application and Store • Allows Storage Schema and Application to evolve independently • Explicit Operations • Server interactions should be explicit • Build implicit logic on top of explicit operations • Common Textual "EntitySQL" Language for Ad-Hoc queries • Targets: Microsoft SQL Server and third-party databases • RTM: Microsoft Visual Studio 2008 Update H1CY08

  8. LINQ to EntitiesFlexible Mapping to Relational Data • Flexible Mapping • Mapping a single class to multiple tables/views • Mapping to different types of inheritance • Single Table per Class Hierarchy • Separate Table for each Class in a Hierarchy • Shared Table for Base Class members in a Hierarchy • Complex (composite) types • i.e., Street, City, Region, and Zip as "Address" • Directly mapping Many:Many relationships • Mapping to an arbitrary Query • Store Query • Expose arbitrary store query as a storage Table • Entity Query • Express mapping as EntitySQL against storage schema

  9. LINQ to EntitiesFeatures • Customization • Business Logic • Partial Classes, Events, Partial Methods • Update Logic • Generated Update Views • Declarative stored procedures • Optimizations • "Span" related members • NoTracking • Extensibility • Partitioning of Metadata • Flexible Runtime Mapping • Metadata Pluggability

  10. Flexible Mapping with LINQ to Entities

  11. LINQ to DataSetLINQ over Disconnected Cache with Change Tracking • Disconnected Cache • Offline/Remote • Data Aggregation • Application Data • All with Change Tracking • Queryable • Filter, Projection • Joins • Across Tables • Other in-Memory sources • Local expressions • All through Common LINQ syntax • RTM: Microsoft Visual Studio 2008 RTM

  12. LINQ to DataSetTyped and UnTyped • UntypedDataSet • Call AsEnumerable() on DataTable • Reference Fields by Name • Use Field<T>(columnName) • Project out fields for strongly typed result • Typed DataSet • Use strongly typed accessors 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") } ; var query = from customer in northwind.Customers where customer.City == "London" select customer;

  13. Querying Disconnected Data with LINQ to DataSet

  14. Summary • LINQ to SQL – Strongly Typed Database • Emphasis on rapid application development • Direct mapping to Microsoft SQL Server family of databases • Release in Microsoft Visual Studio 2008 RTM • LINQ to Entities – Flexible mapping to existing Schema • Focus on enterprise-grade data scenarios • Flexible Mapping to Microsoft SQL Server and third-party databases • Release in Microsoft Visual Studio 2008 update • CTPs on top of Microsoft Visual Studio 2008 Betas/RTM • LINQ to DataSet – In-Memory Cache w/Change Tracking • All the scenarios where DataSet is useful today • Offline, Disconnected, Aggregation • Change Tracking • ..Plus support for Query Operations • Strongly typed or UntypedDataSet Support • Release in Microsoft Visual Studio 2008 RTM

More Related