José A. Blakeley Partner Architect Microsoft Corporation Michael Pizzo Principal Architect...

114
ADO.NET Entity Framework José A. Blakeley Partner Architect Microsoft Corporation Michael Pizzo Principal Architect Microsoft Corporation

Transcript of José A. Blakeley Partner Architect Microsoft Corporation Michael Pizzo Principal Architect...

Page 1: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Entity Framework

José A. BlakeleyPartner ArchitectMicrosoft Corporation

Michael PizzoPrincipal ArchitectMicrosoft Corporation

Page 2: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

10-12:00 Section 1: Evolution of ADO.NET12:00-1:15 <Lunch>1:15-2:30 Section 2: ADO.NET and LINQ2:30-2:45 <Break>2:45-4:00 Section 3: ADO.NET Entity Framework Deep Dive4:00-4:15 <Break>4:15-5:45 Section 4: Building on ADO.NET

ADO.NET A to Z: Agenda

Page 3: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Evolution of Data Access APIs Proprietary APIs Object Databases Standard SQL Data Access APIs

ODBC, DAO, RDO Componentized Data Access

OLE DB, ADO .NET Data Access

ADO.NET ADO.NET 1.0 Building a Data Platform The ADO.NET Entity Framework

Section 1: Evolution of ADO.NET

Page 4: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Application-specific, monolithic data access Files, hierarchical DBMSs CICS, IMS, etc.

Relational DBMSs emerged DBMS-specific APIs and protocols

OCI, DBLIB, SQL*, TDS, DRDA Embedded SQL

1xN data access problem Each app writes data-source-neutral data

access layer

Proprietary APIs – 70’s & early 80’s

Page 5: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ODBC Common C API for accessing SQL Databases Driver Manager loads DBMS-specific drivers Developed with SQL Access Group, ANSI/ISO

Adopted as SQL-CLI Addendum to SQL92 DAO

"OLE Automation" interface to Microsoft Access Provided Access, VB developers access to ODBC

sources RDO

DAO-style interfaces directly over ODBC Subsumed by DAO "ODBC Direct" mode

SQL APIs – Late 80’s & early 90’s

Page 6: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Transparent Language Persistence C++, Lisp, SmallTalk Transaction support - low throughput Very transparent persistence

Fast navigational performance Object graph loaded to memory Most navigation in memory Object faulting based on memory mapped IO and

pointer swizzling Limited query support

ODMG OQL standard No efficient implementations Limited indexing support

Limited customer acceptance

Object Databases – Mid 90’s

Page 7: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

OLE DB COM-Based Data Access API Relational and non-relational sources

Tables, hierarchies, OLAP, documents Factored interfaces

Providers: SQL, ISAM, Excel, AS400 FS, Exchange Services: cursor engine, shaping, remoting, resource pooling,

transaction enlistment Used by SQL Server internally and externally

SQL Engine, Federated Query, Integration Services,… ADO

"OLE Automation" interface for OLE DB Interface for VB developers

Similar programming model to DAO Introduced disconnected RecordSets

Component Data Access – Late 90’s

Page 8: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Need a managed API for the new .NET Framework Consistency across framework

Explicit separation of connected access from disconnected Connected Model

Lower-level, common API for exposing the functionality native to a data store

Higher level abstractions, common functionality built on top Dataset as “in-memory data cache"

Database independent Predictable semantics, latency, error handling,… Combine data from multiple sources

Support for XML

ADO.NET 1.0 – Early 00’s

Page 9: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Evolution of Data Access APIs ADO.NET 1.0

Architecture Getting Data from a SQL Database Working with Data ADO.NET and XML

Building a Data Platform The ADO.NET Entity Framework

Section 1: Evolution of ADO.NET

Page 10: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Managed Provider

DataReader

CommandConnection

ADO.NET 1.0 Architecture

Controls,Designers,

Code-gen, etc

DataSet

DataAdapter

XmlReader

XmlWriter

OLTP operations,Programmatic Processing,

Frameworks

Page 11: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Getting Data From a SQL DatabaseADO.NET Data Provider Specific to a particular DBMS

Directly exposes consumer interfaces No more COM/Automation dichotomy

ADO.NET DataProvider Object Model Connection

Establishes connection to DataSource Transaction

Explicit Transaction Control Command

Execute SQL statement DataReader

Forward-only, Read-Only Result Stream Fields accessed through strongly typed, indexed accessors

Data store

DataProvider

Connection

CreateCommand()

ExecuteReader()

DataReader

Command ParametersParametersParameters

Page 12: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Relational View of Data Tables, Columns, Rows,

Constraints, Relations Directly create metadata

and insert data Explicit Disconnected Model

Disconnected, remotable object No knowledge of data source or properties

Common Behavior Predictable performance characteristics

Array-like indexing Strong Typing

Working with DataDataSet DataSet

TablesTable

ColumnsColumn

Constraints ConstraintRows

RowRelations

Relation

Page 13: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

DataSet Scenarios Application Data Remoting Results

SOAP, WebMethods, Remoting Caching Results

ASP.NET Cache Persisting results

Save Data as XML, Schema as XSD User interaction

Scrolling, sorting, filtering DataView, DataViewManager

Binding Windows controls

Page 14: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

DataAdapter

Loads a table from a data store and writes changes back. Exposes two methods:

Fill(DataSet,DataTable) Update(DataSet,DataTable)

Provides mappings between tables & columns

User provides insert/update/delete commands Allows use of Stored Procedures CommandBuilder component available

Allows single DataSet to be populated from multiple different datasources

Data store

DataAdapter

MappingsMappingsMappings

InsertCommand

UpdateCommand

DeleteCommand

SelectCommand

Fill() Update()

DataSet

Page 15: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET and XML The DataSet

Loads/saves XML data into/out of DataSet Schema can be loaded/saved as XSD Schema can be inferred from XML Data

The DataSet can be associated with an XmlDataDocument Exposes a relational view over structured XML

According to the DataSet schema Allows strong typing, control binding, relational access of XML

data Allows XML tools (schema validation, XSL/T, XPath queries)

against relational data Preserves full fidelity of XML Document

Page 16: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET 1.0

demo

Page 17: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Evolution of Data Access APIs ADO.NET 1.0 Building a Data Platform

Why a Conceptual Model? The Microsoft Entity Data Model Entity SQL

The ADO.NET Entity Framework

Section 1: Evolution of ADO.NET

Page 18: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Writing queries is difficult No help from compiler Results are untyped rectangular records

Database Schemas optimized for storage concerns Relational Tables contain flat, homogenous records

Implicit Logic Embedded in Application Brittle, Hard to maintain

Lack of common syntax across relational databases

The ProblemProgramming Data is Hard

Page 19: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Rapid Development Strongly typed queries Strongly typed results with Business Logic

Lower TCO Work with an explicit data model

Types, Inheritance, Relationships, Complex Properties,… Decouple application from storage schema

Better Portability Common query language across disparate sources

The OpportunityIncrease Developer Productivity

Page 20: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Applications Today… Implicitly Contain the Data

Model Logic and Model Intertwined Conceptual Mismatch Often encapsulate in a

"Data Access Layer"

Where’s Your Data Model?

Page 21: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Applications Today… Implicitly Contain the Data

Model Logic and Model Intertwined Conceptual Mismatch Often encapsulate in a

"Data Access Layer"

Where’s Your Data Model?

The Need… Applications work with a well

Defined Model Storage Schema Abstraction

Declarative mapping between application and storage models

No brittle, hard-coded mapping

Page 22: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

An extended relational model with Entity-Relationship Model concepts Entity Types

Strong type with Identity Inheritance Scalar/Complex properties

EntitySets Hold instances of Entity Types

Similar to relational tables Can have multiple Entitysets of the same EntityTypes

Relationships ("Associations") Named relationships between Entities 0..1:*, 0..1:0..1, 1:1, 1:M, M:N Navigation may be exposed as NavigationProperties on

EntityTypes AssociationSets

Contains instances of associations May be queried directly

EntityContainers Contains EntitySets, AssociationSets

The Microsoft Entity Data Model

SalesPerson

EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……

SalesPerson

EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = …CarLicenseNum = ……

SalesPerson

EmployeeID = 729742LoginID = peteTitle = "Developer"VacationHours = 0…ExpenseAccount = true…

SalesPerson

EmployeeID = 294272LoginID = adamTitle = "Dev Lead"VacationHours = 0…

Reports

Manager

11

N

Page 23: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

SQL extended to support the Entity Model SELECT Value

Promotes a single column to the record Entity construction

Useful in DefiningQueries Type Operations

OFTYPE, TREAT,… Relationship Navigation

Navigate(), . Manipulation of Keys

Key(), Ref()/DeRef(), CreateRef, Row() Other

Set()/Flatten() CrossApply, OuterApply Skip/Limit

EntitySQL

Page 24: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access in the 80s ADO.NET 1.0 Building a Data Platform ADO.NET Entity Framework Introduction

Overview Entity Designer EntityClient Object Services

Section 1: Evolution of ADO.NET

Page 25: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Entity Framework

Page 26: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access in the 80s ADO.NET 1.0 Building a Data Platform The ADO.NET Entity Framework

Overview Entity Designer EntityClient Object Services

Section 1: Evolution of ADO.NET

Page 27: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Define / Modify Conceptual Entity Model Define Entities, Associations, Functions Create from scratch or Reverse-Engineer from

database Define mapping to Relational Store

Generate/Refresh storage schema definition from Database

Generate CLR Objects for Entity Model Partial classes

Generate runtime metadata .csdl, .msl, .ssdl files or embed as resources

Entity Designer

Page 28: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

No support for: "Model-First" Complex Types Abstract Types Multiple Entity Sets per Type

Practical limitation of ~120 Entities No design support for SSDL

Must manually edit XML Refresh overwrites manual changes to SSDL

Lack of Automatic Pluralization support Modify EntitySet names in model

Entity Designer V1 Limitations

Page 29: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Entity Designer

demo

Page 30: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access in the 80s ADO.NET 1.0 Building a Data Platform The ADO.NET Entity Framework

Overview Entity Designer EntityClient Object Services

Section 1: Evolution of ADO.NET

Page 31: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

…is an ADO.NET Data Provider EntityConnection

Metadata/Mapping specified in ConnectionString Can also load from XmlReader

EntityCommand Canonical EntitySQL syntax Stored Procedure Support Access to Provider-specific SQL

EntityDataReader Rectangular results described through IDataReader Typing, Polymorphism described through

IExtendedDataReader Limitations

No DML, DDL Call Functions in SSDL

No DataAdapter

EntityClient

Page 32: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

EntityClient

demo

Page 33: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access in the 80s ADO.NET 1.0 Building a Data Platform The ADO.NET Entity Framework

Overview Entity Designer EntityClient Object Services

Section 1: Evolution of ADO.NET

Page 34: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Object Services

Provides core object service abstractions Context, identity, state management Query, object materialization ObjectContext, ObjectQuery<T>, ObjectStateManager

Tools generate partial classes from EDM models Strongly typed collections Navigational patterns, relationship fix up Users can extend the partial classes to add business logic

Provides query and update interfaces LINQ integration, Entity SQL Strongly typed CRUD operations (add, delete, savechanges)

Page 35: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Object Services

demo

Page 36: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Questions?

Page 37: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.
Page 38: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Introduction to LINQLINQ to SQLLINQ to EntitiesLINQ to DataSet

Section 2: ADO.NET and LINQ

Page 39: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Queries as first-class concept in .NET languages

Builds on several language features Type inference, Delegates, Generics

Enabled by Lambda expressions Anonymous types Object initialization expressions Extension methods Query expressions

Introduction to LINQ

Page 40: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Introduction to LINQ

// Lambda Expressionsstring[] names = { "Luis", "Mary", "Mike", "Jose" };Display( names, s => s.Length > 3);

// Anonymous Types and object initializationvar emp = new { Name = "Mary", Company = "Microsoft",

Age = 30 };// Extension Methodspublic static class ExtensionMethods { public static void Display<T>(this T[] names,

Func<T, bool> filter) {foreach (T s in names) {

if (filter(s)) Console.WriteLine(s);}

}}// Query Expressionsvar query = from c in Customers

where c.Discount >= 3.0 && c.Discount < 4.0select new { c.Name, Perc = c.Discount / 100.0 };

Page 41: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Introduction to LINQ LINQ to SQL

Design Points Features Demo

LINQ to EntitiesLINQ to DataSet

Section 2: ADO.NET and LINQ

Page 42: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

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

LINQ to SQLDirect Mapping

Page 43: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

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

Page 44: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

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

LinqDataSource for use in ASP.NET

LINQ to SQLFeatures

Page 45: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to SQL

demo

Page 46: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Introduction to LINQLINQ to SQL LINQ to Entities

Design Points Features Demo

LINQ to DataSet

Section 2: ADO.NET and LINQ

Page 47: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

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

Targets: Microsoft SQL Server and third-party databases

Page 48: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

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

EntityDataSource for use from ASP.NET

Page 49: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to Entities

demo

Page 50: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Introduction to LINQLINQ to SQLLINQ to Entities LINQ to DataSet

Section 2: ADO.NET and LINQ

Page 51: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to DataSetLINQ over Disconnected Cache with Change Tracking

Disconnected Cache Offline/Remote Data Aggregation Application DataAll with Change Tracking

Queryable Filter, Projection Joins

Across Tables Other in-Memory sources

Local expressionsAll through Common LINQ syntax

Page 52: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to DataSetTyped and UnTyped

Untyped DataSet Call AsEnumerable() on DataTable Reference Fields by Name

Use Field<T>(columnName) Project out fields for strongly typed result

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;

Typed DataSet Use strongly typed accessors

Page 53: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to DataSet

demo

Page 54: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

LINQ to SQL Strongly Typed Database Emphasis on rapid application development Direct mapping to Microsoft SQL Server family of databases

LINQ to Entities Flexible mapping to existing Schema Focus on enterprise-grade data scenarios Flexible Mapping to Microsoft SQL Server and third-party

databases

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 Untyped DataSet Support

Summary: ADO.NET and LINQ

Page 55: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Questions?

Page 56: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.
Page 57: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Customizing Data Classes Entity Framework Mapping Scenarios Database Design Considerations Advanced Mapping Techniques

Section 3: ADO.NET Entity Framework Deep Dive

Page 58: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Partial Classes Add business logic, methods, non-persisted

properties to partial classes Codegen Customization

Add custom logic to Property, Type Generation Attributes, Interfaces, Members, BaseClass,… Getters, Setters, BackingField, Return Type,…

Custom Classes Write your own classes that

Derive from EntityObject, or Implement interfaces:

IEntityWithKey, IEntityWithChangeTracker, IEntityWithRelationships

Customizing Data Classes

Page 59: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Customizing Data Classes

demo

Page 60: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Customizing Data Classes Entity Framework Mapping Scenarios

Core Mapping Scenarios Function Mapping Mapping Limitations

Database Design Considerations Advanced Mapping Techniques

Section 3: Entity Framework Deep Dive

Page 61: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

EntitySets map to Table(s) EntityTypes, Properties can be renamed A single EntitySet may be mapped to multiple tables Different EntityTypes in a hierarchy can be mapped to:

Different columns within a table or different tables An EntitySet may be mapped to a subset of the rows

within a table AssociationSets map to tables with foreign keys

M:N relationships map to join table 0..1 : * relationships may be "co-located" Relationships may map to/from subtypes in a hierarchy Can have "Owning" relationships

Core Mapping Scenarios

Page 62: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Functions exposed through Function Imports Parameters may be mapped Stored Procedures can return different results

Mapping CUD operations to Functions Insert, Update, Delete operations

Function Mapping

Page 63: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Must use a common EntityKey throughout type hierarchy

Relationships must be based on EntityKey EntityKey can't contain reference

Function results must be mapped to EntityTypes Can't Map multiple entities to different columns

of a single row If used, modification functions must include all

CUD operations on EntitySet and References Can't map Multiple Results from a Stored Proc No Support for Composable TVFs in V1

Core Mapping Limitations

Page 64: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Use a common PK… For all tables in a Hierarchy When splitting information across tables For Relationships

Hierarchy Models Single Table per Hierarchy generally results in

simpler queries (fewer joins) Separate table for each subtype when most

queries are against a single Subtype Separate table for additional subtype columns

When most queries are against supertype

Database Design Considerations

Page 65: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Customizing Data Classes Entity Framework Mapping Scenarios Database Design Considerations Advanced Mapping Techniques

Anatomy of an .edmx file Complex Types Custom Mapping

Section 3: Entity Framework Deep Dive

Page 66: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Conceptual Schema Definition (CSDL) Container

EntitySets AssociationSets

Entity Types Association Types

Storage Schema Definition (SSDL) Same Structure as CSDL

Mapping Definition (MSDL) Mapping for EntitySets, AssociationSets

Anatomy of an .edmx File

Page 67: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Conceptual Schema Definition (CSDL)<Schema Namespace="AdventureWorksModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"> <EntityContainer Name="AdventureWorksEntities"> <EntitySet Name="Contacts"

EntityType="AdventureWorksModel.Contact" /> <AssociationSet Name="ManagerEmployees"Association="AdventureWorksModel.ManagerEmployee"> <End Role="Employees" EntitySet="Contacts" /> <End Role="Manager" EntitySet="Contacts" /> </AssociationSet></EntityContainer> <EntityType Name="Contact"> <Key> <PropertyRef Name="ContactID" /> </Key> <Property Name="ContactID" Type="Int32" Nullable="false" /> <Property Name="Title" Type="String" /> <Property Name="FirstName" Type="String" Nullable="false" /> <Property Name="LastName" Type="String" Nullable="false" /></EntityType> <Association Name="ManagerEmployee"> <End Role="Employees" Type="AdventureWorksModel.Employee" Multiplicity="*" /> <End Role="Manager" Type="AdventureWorksModel.Employee" Multiplicity="0..1" /></Association> </Schema>

Page 68: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Storage Schema Definition (SSDL)<Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">  <EntityContainer Name="HumanResources"> <EntitySet Name="Contact"

EntityType="AdventureWorksModel.Store.Contact" Schema="Person" /> <AssociationSet Name="FK_Employee_Employee_ContactID"

Association= "AdventureWorksModel.Store.FK_Employee_Employee_ContactID"> <End Role="Employees" EntitySet="Employee" /> <End Role="Manager" EntitySet="Employee" /> </AssociationSet> </EntityContainer>  <EntityType Name="Contact"> <Key> <PropertyRef Name="ContactID" /> </Key> <Property Name="ContactID" Type="int" Nullable="false"

StoreGeneratedPattern="Identity" /> <Property Name="Title" Type="nvarchar" /> <Property Name="FirstName" Type="nvarchar" Nullable="false" /> <Property Name="LastName" Type="nvarchar" Nullable="false" /> </EntityType>  <Association Name="FK_Employee_Employee_ContactID"> <End Role="Employees" Type="AdventureWorksModel.Store.Employee" Multiplicity="*" /> <End Role="Manager" Type="AdventureWorksModel.Store.Employee" Multiplicity="0..1" /></Association>

</Schema>

Page 69: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Mapping Definition (MSL)<Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"> <EntityContainerMapping StorageEntityContainer="HumanResources"

CdmEntityContainer="AdventureWorksEntities"> 

<EntitySetMapping Name="Contacts" TypeName="AdventureWorksModel.Contact" StoreEntitySet="Contact">

<ScalarProperty Name="ContactID" ColumnName="ContactID" /> <ScalarProperty Name="Title" ColumnName="Title" /> <ScalarProperty Name="FirstName" ColumnName="FirstName" /> <ScalarProperty Name="MiddleName" ColumnName="MiddleName" /> <ScalarProperty Name="LastName" ColumnName="LastName" /> </EntitySetMapping>

<AssociationSetMapping Name="ManagerEmployees"

TypeName="AdventureWorksModel.ManagerEmployee" StoreEntitySet="Employee"> <EndProperty Name="Employees"> <ScalarProperty Name="ContactID" ColumnName="ContactID" /> </EndProperty> <EndProperty Name="Manager"> <ScalarProperty Name="ContactID" ColumnName="ManagerID" /> </EndProperty> <Condition ColumnName="ManagerID" IsNull="false" /> </AssociationSetMapping>  </EntityContainerMapping></Mapping>

Page 70: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Customizing Data Classes Entity Framework Mapping Scenarios Database Design Considerations Advanced Mapping Techniques

Anatomy of an .edmx file Complex Types Custom Mapping

Section 3: Entity Framework Deep Dive

Page 71: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Complex Types Define your Complex Type in CSDL<ComplexType Name ="FullName"> <Property Name="Title" Type="String" /> <Property Name="FirstName" Type="String" Nullable="false" /> <Property Name="MiddleName" Type="String" /> <Property Name="LastName" Type="String" Nullable="false" /></ComplexType>

<EntityType Name="Contact"> <Key> <PropertyRef Name="ContactID" /> </Key> <Property Name="ContactID" Type="Int32" Nullable="false" /> <Property Name="Name" Type="Self.FullName" Nullable="false"/><!-- … --></EntityType>

Use your ComplexType in your Entities

Map the Complex Type in your MSL<EntitySetMapping Name="Contacts" TypeName="AdventureWorksModel.Contact"

StoreEntitySet="Contact"> <ScalarProperty Name="ContactID" ColumnName="ContactID" /> <ComplexProperty Name="Name"> <ScalarProperty Name="Title" ColumnName="Title" /> <ScalarProperty Name="FirstName" ColumnName="FirstName" /> <ScalarProperty Name="LastName" ColumnName="LastName" /></ComplexProperty></EntitySetMapping>

Page 72: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Entity Framework Mapping Scenarios Database Design Considerations Customizing Data Classes Advanced Mapping Techniques

Anatomy of an .edmx file Complex Types Custom Mapping

Section 3: Entity Framework Deep Dive

Page 73: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Multiple EntitySets of the same EntityTypeSpecify the same EntityType in multiple EntitySet

definitions Useful for partitioned data

Split Model Across FilesReference other CSDL, MSL using <Using/> Common SSDL across Referenced MSL files Useful for:

Dealing with large models Partitioning model between users

Customize Conceptual Definition

Page 74: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Specify Custom Mapping to exposed tablesSpecify the EntitySQL that describes the EntitySet

mapping using <QueryView/> Use ModificationFunctionMappings to update Useful for:

Getting around mapping limitations Different Keys in Hierarchy Relationships on non-Key fields Splitting an Entity between tables with different

keys

Customize Mapping Definition

Page 75: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

In-Line Function Definitions:Expose arbitrary command as a function using

<CommandText/> Useful for:

Defining client side functions Defining ModificationFunctionMappings

Change the columns used as Keys Useful for hierarchies without a common key

Change the underlying table:Specify table using the store:Table attribute Useful for exposing the same table as multiple

targets in SSDL

Customize the Storage View

Page 76: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

In-Line Table DefinitionsExpose a native SQL command as a virtual table

using <DefiningQuery/> Use ModificationFunctionMappings to update Useful for:

Ultimate escape hatch for mapping to storage constructs

Utilizing provider-specific commands Composing parameterless TVFs Adding query hints Provider-specific datatypes

Tip: After modifying SSDL, don’t refresh from Database; instead add to new model and Copy/Paste

Customize the Storage View

Page 77: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Custom Mapping

demo

Page 78: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Questions?

Page 79: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.
Page 80: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access Across Tiers Entity Framework Remoting Entity DataSourceControl ADO.NET Data Services

ADO.NET and SQL ServerFuturesSummary: ADO.NET A to Z

Section 4: Building on ADO.NET

Page 81: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Generated Entities are DataContract Serializable Graph Serialization for current values

Track Changes on Client For Optimistic Updates Send original and current For “Last Writer Wins” just send current Use EntityReference to set related Key Values

Apply changes on server Inserts:

Call ObjectContext.AddObject() Updates:

Attach (or query for) Original Entity Call ObjectContext.ApplyPropertyChanges()

Deletes: Attach (or query for) Original Entity Call ObjectContext.DeleteObject()

Call SaveChanges() when done

Entity Framework Remoting

Page 82: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Entity Framework Remoting

demo

Page 83: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Create an ASP.NET Web Application Define or reference your Entity Data Model Add an EntityDataSource Control Configure the EntityDataSource Control

Set NamedConnection and DefaultContainer Set EntitySetName, select properties to display Specify Filter, Ordering, Grouping, Span, TypeFilter

Include Parameters from: Controls, Cookies, QueryString, Form, Session

Specify support for Insert, Update, Delete Bind DataSourceControl to grid, dropdown,…

EntityDataSource Control

Page 84: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Entity Data Source Control

demo

Page 85: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Data Service Publish your Data Model as a REST-based Web Service Supports pluggable DataServiceProviders

EntityFramework, LINQ , Custom DataServiceProviders Protocol

Model-based Contract Uniform Interface

REST-style URI-based addressing CRUD using standard HTTP verbs

Format Independence: Results as ATOM, JSON Shared with SQL Server Data Services, LIVE, …

Extensibility Query Interceptors Service Operations

ADO.NET Data ServicesData Services for the Web

Page 86: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Consuming Data Services Any HTTP client

From Any Browser Specify URLs for query, insert, update, delete

LINQ Enabled Silverlight & .NET Framework Client Library Build queries using LINQ Results as generated or hand-coded objects Save changes back to Service

Future ASP.NET Data Source Control AJAX Client Library (CodePlex)

ADO.NET Data ServicesData Services for the Web

Page 87: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Data Services

demo

Page 88: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access Across Tiers ADO.NET and SQL Server

New data Types Table Valued Parameters New Date Types Spatial: Geography, Geometry Hierarchy Id

Asynchronous Operations MultipleActiveResultSets SqlBulkCopy SqlNotifications SQL Server Functions callable from EF

Futures

Section 4: Building on ADO.NET

Page 89: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

New SQL Server 2008 Data Types

Table-valued Parameters Date Types

Date, Time, DateTimeOfsset, DateTime2 Spatial: Geometry and Geography HierarchyId Sparse Columns File Stream

Page 90: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Input parameters of Table type on SPs/Functions

Optimized to scale and perform better for large data

Behaves like BCP in serverSimple programming modelStrongly typedReduce client/server round trips Do not cause a statement to recompile

Table-valued Parameters (TVP)

CREATE TYPE myTableType AS TABLE (id INT, name NVARCHAR(100),qty INT);

CREATE PROCEDURE myProc (@tvp myTableType READONLY) AS UPDATE Inventory SET

qty += s.qty FROM Inventory AS i INNER JOIN @tvp AS tvp ON i.id = tvp.idGO

Page 91: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Table-valued Parameters (TVP) TVP Client Stack Support Fully supported in ADO.Net 3

New Parameter type: SqlDbType.Structured Parameters can be passed in multiple ways

DataTable IEnumerable<SqlDataRecord> (fully streamed) DbDataReader

Page 92: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Table-valued Parameters ADO.NET Example using DataTableUsing (MyConnection){ //Create a data table DataTable dt = new DataTable(“TVPOrdersDataTable”); dt.Columns.Add(“ProductType”, typeof(string)); dt.Columns.Add(“Quantity”, typeof(int)); // Add rows dt.Rows.Add(“Canon Digital Camera”, 20); dt.Rows.Add(“June”, 10); dt.Rows.Add(“Xbox-360”, 8);

// Create a command and bind parameter SqlCommand tvp_cmd = new SqlCommand(“sp_UpdataInventory”,

MyConnection); SqlParameter tvpParam = tvp_cmd.Parameters.AddWithValue(

@OrdersTvp, dt); //Execute command tvp_cmd.ExecuteNonQuery();

Page 93: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

New SQL Server 2008 Date Types

Page 94: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

New DateTimeOffset

SqlCommand command = new SqlCommand(string.Empty, sqlConnection);

command.CommandText = "insert into MoviesRented values(@customerId, @MovieID, @RentalDate,

@DueDate)";….// create a parameter for RentalDateSqlParameter rentDateParam = new SqlParameter("RentDate", System.Data.SqlDbType.DateTimeOffset); rentDateParam.Value = DateTimeOffset.Now; command.Parameters.Add(rentDateParam);

// create a parameter for DueDateSqlParameter dueDateParam = new SqlParameter("DueDate", System.Data.SqlDbType.DateTimeOffset); dueDateParam.Value = DateTimeOffset.Now.AddDays(7); command.Parameters.Add(dueDateParam);….

Page 95: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

New DateTimeOffset

// create a command to get the DueDate SqlCommand command =

new SqlCommand(String.Empty, sqlConnection); command.CommandText = "select DueDate from MoviesRented where MovieId = @MovieId";… // Execute the DataReader // using (SqlDataReader dataReader = command.ExecuteReader()) { if (dataReader.Read() == false) {

Console.WriteLine("Movie has not been rented");

}DateTimeOffset dueDate =

dataReader.GetDateTimeOffset (0); Console.WriteLine("Movie due back on : {0}", dueDate); }

Page 96: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Asynchronous Operations

SqlClient provides true async I/O Opening connections Executing commands

Client applications don’t block UI Server applications execute multiple requests without

blocking threads Consistent with .NET async pattern

BeginXXX and EndXXX methods Use IAsyncResult to poll or block …Or use a callback

Callback is called in a different thread

Page 97: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Asynchronous Example

// Poll for completionIAsyncResult result = cmd.BeginExecuteReader();while(!result.IsCompleted) {

// do some work}SqlDataReader reader = cmd.EndExecuteReader(result);

// Use a CallbackIAsyncResult result = cmd.ExecuteReader(

new AsyncCallback( myDataCallback ));

// do other work…

// optionally wait using sync objectresult.WaitHandle.WaitOne();

public void myDataCallback( IAsyncResult result ) {SqlDataReader reader = cmd.EndExecuteReader(result);

}

Page 98: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Multiple Active ResultSets

Connection String attribute:MultipleActiveResultSets=True

Enables multiple results per connection Performance and scalability gain

Multiple sessions per physical connection Reduction in client and server resources usage Avoids pooling/connection initialization logic Combine with async for maximum perf

Single result per command Available against SQL 2005 and newer

Page 99: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Deliver a message to a queue when a change occurs that would affect results Rows in the result changed/deleted New rows added that would have been in the result

Client specifies message body and delivery queue Any authorized client can check for notifications

Poll or blocking query Use SqlDependency for ease of use Use NotificationContext to automatically enlist

any commands w/in context Enables notification w/LINQ to SQL and LINQ to Entities

Notifications

Page 100: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Notification Example

public SqlDataReader GetProducts(int Category) {SqlCommand cmd = new SqlCommand(

"Select ProductName, UnitPrice from Products " +"where CategoryID = @CatID", cnn);

cmd.Parameters.Add("@CatID",Category);cmd.Notification = new SqlNotificationRequest(

Category.ToString(), // message"myQueue", // message body3000); // timeout

return cmd.Execute();}

public void WaitForChanges() {SqlCommand cmd = new SqlCommand(

"Receive message_body from myQueue " +"WITH wait_for_results", cnn);

cmd.CommandTimeout = 0;int category = (int)cmd.ExecuteScalar();Console.WriteLine("Category {0} changed.",category);

}

Page 101: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Bulk-Copy

High-perf bulk load Load Data from several data sources

IDataReader, DataTable, DataRow[] No support for BCP files and BCP out

public void LoadFromDataReader(IDataReader reader){

// Copy the Data to SqlServerSqlBulkCopy bcp =

new SqlBulkCopy( connectString );bcp.DestinationTableName = "Customers";bcp.WriteToServer( reader );

}

Page 102: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

User-Defined Types

SqlClient natively supports UDTs UDTs are CLR types

Data readers return instances of UDTs Parameters can be instances of UDTs

SQLOLEDB also provides UDT support Using COM/interop

Assembly location Application can use strong typed references to local assembly

Methods execute on client Assembly downloaded if needed

Must be granted download priviledge on assembly Security warning on download Class is limited by security policy, application

domain permissions Access objects through reflection

Page 103: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

UDT Example

SqlConnection cnn = new SqlConnection(connectString);cnn.Open();SqlCommand cmd =

new SqlCommand("SELECT p FROM PointTable", cnn );SqlDataReader reader = cmd.ExecuteReader();while( reader.Read() ) {

Point point=(Point)reader[0];Console.WriteLine(

"x:{0}, y:{1}", point.x, point.y );}cnn.Close();

Page 104: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

SQL Server Functions in EntiySQLAggregatesAVGCHECKSUM_AGGCOUNTCOUNT_BIGMAXMINSTDEVSTDEVPVARVARP

String FunctionsASCIICHARCHARINDEXDIFFERENCELEFTLENLOWERLTRIMncharPATINDEXQUOTENAMEREPLACEREPLICATEREVERSERIGHTRTRIMSOUNDEXSPACESTRSTUFFSUBSTRINGUNICODEUPPER

Math FunctionsABSACOSASINATANATN2CEILINGCOSCOTDEGREESEXPFLOORLOGLOG10PIPOWERRADIANSRANDROUNDSIGNSINSQRTSQUARETAN

Date FunctionsDATEADDDATEDIFFDATENAMEDATEPARTDAYGETDATESYSDATETIMESYSUTCDATETIMESYSDATETIMEOFFSETGETUTCDATEMONTHYEAR

System FunctionsDATALENGTHCHECKSUMNEWIDCURRENT_TIMESTAMPCURRENT_USERHOST_NAMEUSER_NAMEISNUMERICISDATE

Page 105: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET and SQL Server

demo

Page 106: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Data Access Across TiersADO.NET and SQL Server Futures

Section 4: Building on ADO.NET

Page 107: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Entity Framework Futures

Tool Support Model-First Support for Larger Models Complex Types Exensibility

Data Class Support Pure POCO Templates

Improved Mapping Support Composable TVFs

New Entity Services Synchronization, Offline SSRS integration

Page 108: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

DataSet Queryable, remoteable In-memory relational collection

DBMS-Specific ADO.NET Data Provider Direct access to native store syntax, types

EntityClient Canonical Ad hoc queries with Flexible Mapping

LINQ to SQL Strongly typed Microsoft SQL Server schema LinqDataSource for use in ASP.NET

Summary: ADO.NET Data Access Components

Page 109: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ObjectServices Strongly typed Entity Model with Flexible Mapping LINQ to Entities

Strongly typed Queries EntitySQL

Complex Queries, Ad-hoc Queries, Provider-specific Functions EntityDatasource

Simple ASP.NET Integration ADO.NET Data Services

Standard, Robust, REST-based service Easy to use, Highly Extensible .NET Client for simple programming

SummaryADO.NET Data Access Components

Page 110: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Entity Framework V1 delivers… Applications work in terms of a rich Conceptual Model

Strongly typed LINQ queries Ad-hoc ESQL queries Untyped EntityClient

Flexible mapping to existing storage schemas, DBMSs Tool support for generating model, mapping

ADO.NET Entity Framework promises… More Mapping Flexibility Richer Entity Model Concepts Less Intrusive Persistence Logic Better support for provider-specific functions Better tooling for model/code-driven development More services: Synchronization, Data Definition,…

Summary: ADO.NET Entity Framework

Page 111: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

ADO.NET Forum:http://blogs.msdn.com/adonet/default.aspx

LINQ to SQL Forumhttp://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=2035&SiteID=1 ADO.NET Entity Framework Forum:http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=533&SiteID=1

ADO.NET Entity Framework Design BLOG:http://blogs.msdn.com/efdesign/

Danny Simmons’ BLOG:http://blogs.msdn.com/dsimmons/default.aspx

Summary:For More Information…

Page 112: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

Questions?

Page 113: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.
Page 114: José A. Blakeley Partner Architect Microsoft Corporation  Michael Pizzo Principal Architect Microsoft Corporation.

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.