slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ADO.NET 3.0 – Entity Data Model PowerPoint Presentation
Download Presentation
ADO.NET 3.0 – Entity Data Model

Loading in 2 Seconds...

play fullscreen
1 / 23

ADO.NET 3.0 – Entity Data Model - PowerPoint PPT Presentation


  • 64 Views
  • Uploaded on

ADO.NET 3.0 – Entity Data Model. Gert E.R. Drapers Chief Software Architect Visual Studio Team Edition for Database Professionals Microsoft Corporation http://blogs.msdn.com/gertd. Agenda. ADO.NET Entity Framework Introduction Application Scenarios Direct Mapping

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ADO.NET 3.0 – Entity Data Model' - elizabeth-stout


Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ado net 3 0 entity data model

ADO.NET 3.0 – Entity Data Model

Gert E.R. Drapers

Chief Software Architect

Visual Studio Team Edition for Database Professionals

Microsoft Corporation

http://blogs.msdn.com/gertd

agenda
Agenda
  • ADO.NET Entity Framework Introduction
  • Application Scenarios
    • Direct Mapping
    • Flexible Mapping Scenarios
    • Extensibility
  • Usage Best Practices
  • Summary
the entity framework
The Entity Framework

The Entity Data Model

ADO.NET Entity Framework

LINQ over

Entities

ADO.NET 2.0

Object Services

LINQ over

Dataset

Dataset

ADO.NET Providers

Entity Client

Language Integrated Query (LINQ)

Dataset

<book>

<title/>

<author/>

<year/>

<price/>

</book>

ADO.NET Providers

entity framework overview

CQT

Entity Framework Overview

EDM

MetaData

LINQ

ESQL

Native

SQL

ESQL

CQT

CQT

LINQ to Entities

Object

Metadata

Object Services

O-C

Map

EntityClient Data Provider

Client View Engine

Conceptual

Schema

C-S

Map

DataReader

DataReader

IEnumerable<T>

ADO.NET Data Provider

Store Schema

ADO.NET Data Provider

ADO.NET Data Providert

edmgen exe
EDMGEN.EXE
  • Generates the model files
  • Model.ssdl (Store Schema Definition Language)
    • Describes tables and columns which map to Entities and Relationships
  • Model.csdl (Conceptual Schema Definition Language)
    • Describes the Entity Data Model (incl. EntitySets, EntityTypes, Associations & AssociationsSets)
  • Model.msl (Mapping Specification Language)
    • Describes how the Entity Framework maps between the Conceptual Model (CSDL) and the logical Storage Schema (SSDL)
  • Model.cs or Model.vb
    • Partial class implementing the model created
direct mapping
Direct Mapping
  • Scenario
    • Database schema provides appropriate application model
  • Benefits
    • Relationships
    • Common Extended Query Language
    • Common Queryable Schema
    • Common Metadata Services
    • Object Services
      • Business Logic
      • Identity Management
      • Change Tracking
    • Language Integrated Query (LINQ)
flexible mapping
Flexible Mapping
  • Scenario
    • Database schema doesn't match application model
  • Benefits
    • Richer Application Data Model
      • Inheritance
      • M:N Relationships
    • Richer Mapping
      • Inheritance options (TPH, TPT, TPC)
      • Stored Procedures
      • Entities split across tables
    • Decouples application model from storage schema
      • Multiple application models for same store
      • Same application model over different storage schemas
      • Independent evolution of application model/storage schema
extensibility
Extensibility
  • Scenario: Building a customizable framework
  • Benefits
    • Flexible run-time mappings
      • i.e., Language-specific mappings
    • Mapping to "Extensible Schemas"
      • EntityViews
    • Vertical partitioning of framework and extensions
      • Separate mappings
      • Derived types
    • Extending data classes
best practices
Best Practices
  • Should I use Objects or DataRecords?
  • How long should I hold an ObjectContext?
  • Which mapping techniques should I use?
  • When should I used Stored Procedures or Table Valued Functions?
  • How should I extend data classes?
  • When should I write my own data classes?
  • When should I use Custom Serialization?
  • Should I use LINQ, Query Builder Methods, or eSQL?
  • Should I use LINQ to SQL or LINQ to Entities?
objects or datarecords
Objects or DataRecords?
  • Objects (IEnumerable<T>)
    • Strong typing
    • Business logic
    • Updating
    • Example: Interactive Windows application
  • Data Records (IExtendedDataReader)
    • Performance for read-only streaming
      • Sequential access
      • Avoid object construction overhead
      • Doesn't require generated classes
    • Example: Directly serializing results to a Web response
holding objectcontext
Holding ObjectContext
  • Web scenarios
    • Typical pattern: Create, Use, dispose
    • ObjectContext holds resources
      • Connections
      • Object References
    • Use NoTracking for read-only scenarios
  • Windows Forms scenarios
    • Hold as long as application interacts with results
    • ObjectContext mantains state
      • Identity resolution
      • Change tracking
    • New ObjectContext for each new query
      • Ensures data is fresh
mapping techniques
Mapping Techniques
  • Database views
    • Common access patterns across applications
      • Optimization of access paths through Materialized Views
  • Table/View mappings
    • Entity properties map directly to database columns
      • Columns have same meaning throughout hierarchy
  • EntitySQL views in MSL
    • Flexible mappings expressed in EntitySQL
      • Filter based on conditions, read-only properties, non-equality conditions, computed properties, multiple extents mapped to same table
  • Native SQL views in SSDL
    • Mapping on top of native SQL queries
      • Store-specific queries
      • Expose as "EntitySet" to mapping layer
stored procedures and tvfs
Stored Procedures and TVFs
  • Stored Procedures
    • Better control over operations on data within the database
      • Tighter control over operations, permissions
      • Provides level of indirection from storage schema
    • Use for operations that affect state of the database
      • Inserts, updates, deletes
      • Required for updates against ESQL and Native SQL views
    • Can return multiple results in one roundtrip
  • Tabled Valued Functions
    • Better control over access to data within the database
      • Tighter control over operations, permissions
      • Provides level of indirection from storage schema
    • Use for server-side functions that return data
      • Results of TVF are composable within a query
extending data classes
Extending Data Classes
  • Derivation
    • Adding new persistent fields to a base class
      • Derived types
      • Customization extensions
  • Partial Classes
    • Business logic
    • Methods
    • Calculated values
    • Non-persistent fields
    • Custom serialization
  • "Activity" Classes
    • Common operations on data classes
custom data classes
Custom Data Classes
  • Entity Framework-generated data classes
    • Derive from Entity Framework base class
      • Change Tracking, RelationshipManagement
      • Common Notifications, Property Validation
  • Custom data classes
    • Derive from Entity Framework base class
      • Generate common patterns
      • Insert common intermediate class
    • Derive from your own base class
      • Implement IEntity/IEntityWithRelationships
        • Expose EntityKey
        • Notify ObjectContext when data changes
        • RelationshipManager property to do relationship fixup
      • Add attributes for persistent fields
        • How we get O/OC metadata today
    • Investigating "Persistence Ignorance" scenarios
custom serialization
Custom Serialization
  • Default serialization
    • Serialize streams of Entities
      • Doesn't navigate relationships in order to avoid cycles
  • Custom serialization
    • Serialize Graphs
      • Manage relationship serialization to avoid cycles
    • Serialize to different shapes
      • "Entity Projections"
linq query builder or esql
LINQ, Query Builder, or eSQL?
  • LINQ
    • Strongly typed queries
    • Compile-time checking
    • Embedded in your application
    • LINQ-Mapped Canonical Functions
  • ObjectQuery<T> builder methods
    • Queries built from user input
    • Iterative query building
    • Store functions
  • eSQL
    • Dynamic/AdHoc queries
    • Persistent queries
    • Store functions
linq to sql or linq to entities
LINQ to SQL or LINQ to Entities?
  • LINQ to SQL
    • Emphasis on rapid application development
    • Direct mapping
      • Single type hierarchy to single table/view/stored proc/TVF
      • Simple renaming
      • Derive class for update logic/Stored Procedures
    • Direct mapping to Microsoft SQL Server family of databases
    • Microsoft Visual Studio 2008 RTM
linq to sql or linq to entities1
LINQ to SQL or LINQ to Entities?
  • LINQ to Entities
    • Focus on enterprise-grade data scenarios
    • Flexible Mapping to Relational data
      • Mapping a single class across multiple tables/views
      • Mapping to different types of inheritance
      • Directly modeling Many to Many relationships
      • Mapping to an arbitrary query against the store
      • Common model across products
      • Declarative stored procedures
    • Access to Microsoft SQL Server family and other databases through ADO.NET provider model
    • Microsoft Visual Studio 2008 update
the linq project

<book>

<title/>

<author/>

<year/>

<price/>

</book>

Relational

Objects

XML

The LINQ Project

.NET Language Integrated Query

C# 3.0

VB 9.0

Others

LINQ toObjects

LINQ toDataSets

LINQ toSQL

LINQ toEntities

LINQ toXML

summary
Summary
  • Entity Data Model provides an application-oriented data model
    • Entities and relationships
      • Strong typing, polymorphism
  • Client Views provide flexible mapping to your storage schema
    • Entities split between tables, Many:Many relationships, mapping to store queries, etc.
  • Entity Framework lets you opt-in according to your requirements
    • DataReaders/Objects
    • eSQL/QueryBuilder/LINQ
    • Generated/Custom Data Classes
questions

? Questions ?

http://blogs.msdn.com/gertd