Entity Framework Overview
-
Upload
eyal-vardi -
Category
Technology
-
view
3.943 -
download
0
description
Transcript of Entity Framework Overview
Entity Framework
Eyal VardiCEO E4D Solutions LTDMicrosoft MVP Visual C#blog: www.eVardi.com
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Agenda
Data Access History
OO vs. Relational World
EF Architecture
Development Approaches
EF 4.0+ New API
EDM
Conceptual Model
Mapping
StorageModelADO.NET Provider
Entity Client Provider
Object Services
LINQ to Entities
Entity SQL
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Data Access History
2003 - DataSet & DbCommand
2005 – DataSet &Table
Adapters
2008 – LINQ to SQLEF 1.0
2010 - EF 4.0
2011 - EF 4.1
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Entity Framework Flow
LINQ Query Objects SubmitChanges()
SQL Query Rows SQL or Stored Procs
Entity Framework
SQLServer
from c in db.Customerswhere c.City == "London"select new { c.Name, c.Phone }
select Name, Phonefrom customerswhere city = 'London'
Application
Services:- Change tracking- Concurrency control- Object identity
EDMX
ADO.NET Provider
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
OO vs. Relational World
Data Types
Associations
Granularity
Inheritance
Identity
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
EF Architecture
EDM
Conceptual Model
Mapping
StorageModel
SQLServer
ADO.NET Provider
Entity Client Provider
Object Services
LINQ to Entities Entity SQL
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Entity Data Model (EDM)
The EDM is the link between the model and the database.
The EDM is that it decouples your application from the underlying store.
Entity Data Model (EDM)
Conceptual Model (CSDL)
Mapping(MSL)
StorageModel(SSDL)
Storage
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Object Services
Materialization The process of transforming the data obtained from the
Entity Client data provider, which has a tabular structure, into objects.
Change tracking Tracks any changes made to the objects.
Query transformation Translates queries it into a command tree that’s then passed
on to the underlying Entity Client.
Object identities
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Object Services Functions
Querying Querying data as objects Shaping query results Composing queries CRUD Lazy loading Inheritance Navigating relationship
Change tracking Saving changes Attaching objects Detaching objects Serializing objects
Managing Object identities Concurrency Transactions
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Entity SQL & LINQ to Entities
LINQ to Entities - The LINQ dialect that enables typed queries against the model.
Entity SQL - The second way of querying the object model. Entity SQL is string-based. Can be used to retrieve data at low level, directly using the
Entity Client.
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Development Approaches
EDM
Conceptual Model
Mapping
StorageModelADO.NET Provider
Entity Client Provider
Object Services
LINQ to Entities
Entity SQL
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Database First If you already have a database, the Entity
Framework can automatically generate a data
model that consists of classes and properties
that correspond to existing database objects
such as tables and columns.
DB
GeneratedData Model
(.edmx)Database First
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Model First If you don't yet have a database, you can
begin by creating a model using the Entity
Framework designer in Visual Studio.
The designer can generate DDL (data definition language)
statements to create the database.
Generated
DB
Data Model(.edmx)
Model First
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
DB
GeneratedData Model(Classes)
Code First
Code First Whether you have an existing database or not, you
can code your own classes and properties that correspond to tables and columns and use them with the Entity Framework without an .edmx file.
Generated
DB
Data Model(Classes)
Code First
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Why DbContext & DbSet? This API provides a more productive surface
for working with the EF and can be used with the Code First, Database First, and Model First approaches.
Model Discovery
Model Caching
DbSet Initialization
Database Provisioning
* More info click here
DbModel Constructor
ObjectContext Constructor
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
EF 4.1 New API
© 2010 E4D LTD. All rights reserved. Tel: 054-5-767-300, Email: [email protected]
Features That Are Not Supported
features are not supported by the DbContext API. To use these features, use the ObjectContext API.
Compiled queries
MEST (Multiple Entity Sets per Type)
Self-tracking entities. To use the DbContext API in an N-tier application,
consider using WCF Data Services or RIA Services.