ADO'NET 3'0 Entity Data Model - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ADO'NET 3'0 Entity Data Model

Description:

When should I use Custom Serialization? Should I use LINQ, Query Builder Methods, or eSQL? ... Custom serialization 'Activity' Classes. Common operations on ... – PowerPoint PPT presentation

Number of Views:134
Avg rating:3.0/5.0
Slides: 24
Provided by: downloadM
Category:

less

Transcript and Presenter's Notes

Title: ADO'NET 3'0 Entity Data Model


1
(No Transcript)
2
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

3
Agenda
  • ADO.NET Entity Framework Introduction
  • Application Scenarios
  • Direct Mapping
  • Flexible Mapping Scenarios
  • Extensibility
  • Usage Best Practices
  • Summary

4
The Entity Framework
The Entity Data Model
ADO.NET 2.0
Dataset
ADO.NET Providers
Language Integrated Query (LINQ)
ltbookgt lttitle/gt ltauthor/gt ltyear/gt
ltprice/gt lt/bookgt
5
Entity Framework Overview
EDM MetaData
LINQ to Entities
Object Metadata
Object Services
O-C Map
Conceptual Schema
C-S Map
ADO.NET Data Provider
Store Schema
ADO.NET Data Provider
ADO.NET Data Providert
6
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

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

8
Flexible Mapping
  • Scenario
  • Database schema doesn't match application model
  • Benefits
  • Richer Application Data Model
  • Inheritance
  • MN 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

9
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

10
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?

11
Objects or DataRecords?
  • Objects (IEnumerableltTgt)
  • 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

12
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

13
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

14
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

15
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

16
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

17
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"

18
LINQ, Query Builder, or eSQL?
  • LINQ
  • Strongly typed queries
  • Compile-time checking
  • Embedded in your application
  • LINQ-Mapped Canonical Functions
  • ObjectQueryltTgt builder methods
  • Queries built from user input
  • Iterative query building
  • Store functions
  • eSQL
  • Dynamic/AdHoc queries
  • Persistent queries
  • Store functions

19
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

20
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

21
The LINQ Project
.NET Language Integrated Query
22
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, ManyMany
    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

23
? Questions ?
  • http//blogs.msdn.com/gertd
Write a Comment
User Comments (0)
About PowerShow.com