280 likes | 697 Views
Entity Framework. James Winters. Agenda. Why? What is it? How do you use it? Where do you get more info?. Is EF just another ORM?. Yes and No Entity Domain Model is a very flexible Mapper Should allow for mapping to non-relational data, such as OLAP
E N D
Entity Framework James Winters
Agenda • Why? • What is it? • How do you use it? • Where do you get more info?
Is EF just another ORM? • Yes and No • Entity Domain Model is a very flexible Mapper • Should allow for mapping to non-relational data, such as OLAP • Out of the box all the samples are ORM • Mapping the database to the domain model is currently all EF tooling does • You can hand craft though • Provides mechanisms to create own Providers • Or more likely to download vendor created providers
Architecture SQL Server Relational DBMS Entity Services Applications Reporting Analysis Programming Layers Search Sync Code Gen Linq to Entities Entity SQL Browsing Binding Entity Client – EDM, Entity SQL Domain Modeling Tools Metadata Services Query and Update Pipelines Mapping Mapping Entity Framework Runtime Transactions Modeling Data Providers (ADO.NET patterns) SqlClient OtherClient Non-relational Web Service
Logical Model Object Model (O – Space) Linq Mapped via Attributes Or IPOCO Conceptual Model (C - Space) ADO. Net Provider e.g.EntityClient Mapped via EDMGen or tools Store Model (S-Space) ADO. Net Provider e.g. SqlClient
How is the model stored • As metadata in XML • 3 files • .CSDL (Conceptual Schema Definition Language) • Maps the entity types that you use in your conceptual model • .SSDL (Store Schema Definition Language) • What the DB looks like • .MSL (Mapping Schema Language) • Maps the CSL to the SSDL • Created by Designer tool • Or use EMDGen • Must be available to the runtime • Copy in to bin folder, or use embedded resource build option
Entity Data Model • Tooling provided in CTP 1 • Will be much improved in CTP 2
Querying • 4 strategies • Use the EntityClient Provider • Query C-Space using ADO.Net techniques and Entity SQL • Query the Object Model • Use ObjectQuery<T> and Entity SQL to create objects • Uses ObjectContext to provide the container • Use the generated container to generate objects • Still data oriented, but less so • Use Linq to Entities • Still not totally persistent ignorant, but best we have till Beta 3
The ObjectContext • Can be thought of as the Object Services manager • Encapsulates the mapping and manages the CRUD • Tracks state via the ObjectStateManager • Switch it off for read only via MergeOptions.NoTracking • Entities have one of 5 states • Added • Deleted • Modified • Unchanged • Detached
Persisting Change • When you call SaveChanges() • ObjectContext calculates CRUD options by examining Entity collection and querying state • Concurrency? • Transactions? • Optimisation?
Stored Procedures • For now you have to provide the function declaration in C-Space • And also the mappings to S-Space • Complex type mappings are also hand cranked for now • Simple 1-1 mappings only • Tools in CTP2 have SP and complex type mapping support
References • My Blog • http://www.wintersfamily.plus.com/blogs/JamesWinters/ • ADO.Net Team Blog • http://blogs.msdn.com/adonet/ • The Entity Framework FAQ • http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx
Summary • Shows great promise • It will be the data access technology of choice • Unless Linq to Hibernate takes off • Tooling needs to improve • Or write your own