microsoft data access technologies
Post on 02-Nov-2014
5.284 Views
Preview:
DESCRIPTION
TRANSCRIPT
Data Access Technologies
• DataSet/DataReader• nHibernate• LINQ to SQL• Entity Framework• ADO.NET Data Services
Layered ArchitectureUI UI UI
Business Logic
Data Access / Persistence Layer
Database
Domain Model
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
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)
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)
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
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
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
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)
DemoEntity Framework 4.0
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
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
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
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
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
top related