microsoft data access technologies

17
Data Access [email protected] http://www.joeshirey.com

Upload: david-chou

Post on 02-Nov-2014

5.282 views

Category:

Technology


1 download

DESCRIPTION

Joe Shirey's deck delivered at 2009Q4 Microosft Architect Council events

TRANSCRIPT

Page 1: Microsoft Data Access Technologies

Data Access

[email protected]://www.joeshirey.com

Page 2: Microsoft Data Access Technologies

Data Access Technologies

• DataSet/DataReader• nHibernate• LINQ to SQL• Entity Framework• ADO.NET Data Services

Page 3: Microsoft Data Access Technologies

Layered ArchitectureUI UI UI

Business Logic

Data Access / Persistence Layer

Database

Domain Model

Page 4: Microsoft Data Access Technologies

nHibernate

• Port of the Java Hibernate project• Available in .NET 1.1, 2.0, 3.0, 3.5• Support of many databases– SQL Server, Oracle, DB2, SQLite, PostgreSQL,

MySQL, Firebird, …• XML based mapping and configuration• LGPL licensed• No designer, LINQ support

Page 5: Microsoft Data Access Technologies

ADO.NET 3.5 Technologies

• ADO.NET 3.5– Language Integrated Query (LINQ)– LINQ features except for LINQ to Entities

• ADO.NET 3.5 + SP1– Entity Framework and the Entity Designer– Entity SQL and LINQ to Entities– Provider support for SQL 2008 features

(extensible)

Page 6: Microsoft Data Access Technologies

LINQ Architecture

Objects

<book> <title/> <author/> <price/></book>

XMLRelational

LINQ enabled data sources

LINQ To Objects

LINQ To XML

LINQ enabled ADO.NET

LINQ To Entities

LINQ To SQL

LINQ To DataSet

.NET Language Integrated Query (LINQ)

Page 7: Microsoft Data Access Technologies

LINQ to SQL

• SQL Server only, no provider model• Friendly syntax for mapping tables to objects

with full CRUD functionality• High performance data access layer with data

binding• Code gen with schema-based entities• Limited support for mapping between storage

and entity model (table focused)• Designer support

Page 8: Microsoft Data Access Technologies

Entity Framework

• More of a true Object/Relational (O/R) Mapping Tool

• Designer Support to create a custom map between data tables and domain model

• Is a Data Access Layer• Supports code generation with schema-based

entity mapping• Provider model to support multiple databases

Page 9: Microsoft Data Access Technologies

O/R Mapper SupportFeature LINQ to SQL Entity Framework

Persistence Ignorance/ POCO

Yes, if you convert collections to List<T>

V1 = No, V2 = Yes

Data Mapper Yes, no designer Yes, designer support

Metadata Mapping Yes Yes

Foreign Key Mapping Yes, via EntitySet<T> and EntityRef<T>

V1 = Independent Associations, V2 = Independent or FK Associations

Association Table Mapping No Yes

Lazy Loading Yes, if you don’t convert to List<T>

V1 = Call Load(), V2 = Yes (DeferredLoadingEnabled)

Eager Loading Yes Yes

Identity Map Yes Yes

Unit of Work Yes Yes

Optimistic Concurrency Yes Yes

Page 10: Microsoft Data Access Technologies

New in ADO.NET Entity Framework 4.0• Model-first development• Automatic pluralization• Foreign keys in models• POCO class support• Lazy loading• T4 Code Generation• Template customization• IObjectSet• Virtual SaveChanges• ObjectStateManager control

• Self-tracking entities• SQL generation improvements• More LINQ operator support• LINQ extensibility• ExecuteStoreQuery• ExecuteStoreCommand• SPROC import improvements• Model defined functions• WPF designer integration• Code-Only development (Feature

CTP)

Page 11: Microsoft Data Access Technologies

DemoEntity Framework 4.0

Page 12: Microsoft Data Access Technologies

Multiple Approaches with EF 4.0

• Start with the database– “Database is the truth”– Why? It already exists, or you want low level control over the database– What? Import model into EDMX and tweak

• Start with an EDMX model– “EDMX is the truth”– Why? You want separation from code and database in a declarative

format– What? Create a model and tweak

• Start with .NET classes– “Code is the truth”– Why? Primarily focused on code shape, database is an implementation

detail– What? Define classes in code, adjust shape using contextbuilder

Page 13: Microsoft Data Access Technologies

ADO.NET WCF Data Services

• Formerly called “Astoria”• RESTful data services based on WCF• Relies on HTTP GET, POST, PUT, DELETE verbs to

implement API• Very easy to expose any IQueryable data with a fully

functional RESTful interface• Uniform pattern for data access regardless of data

source• Particularly useful for exposing data to JavaScript

clients

Page 14: Microsoft Data Access Technologies

OData: Open Data Protocol

OData Protocol

Excel/PowerPivot

Visual Studio

.NET Framework

Silverlight

Javascript/AJAX

PHP

Java

.NET Framework

Sharepoint

Sharepoint Services

SQL Server Reporting Services

Windows Azure Table Storage

Codename “Dallas”

ODGI

OData Consumers OData Producers

Page 15: Microsoft Data Access Technologies

Recommendations

• LINQ to SQL– SQL Server only scenarios– Simple table to object mappings

• nHibernate– Pre .NET 3.5 limitations– .NET 3.5 SP1 complex table/object mappings– Database support beyond SQL Server

• Entity Framework– 3.5 SP1 with moderate table/object mappings– 4.0 scenarios– POCO mappings desired– Offline and change tracking

Page 16: Microsoft Data Access Technologies

Recommendations

• WCF Data Services– Access to data primarily not methods– Wrapping EF for standard data access– RESTful services that mainly CRUD based– Protect against future changes– Support for both web and RIA applications

Page 17: Microsoft Data Access Technologies

Data Access

[email protected]://www.joeshirey.com