330 likes | 463 Views
MD. SAIFULLAH AL AZAD, Software Architect . ADO.NET Entity Framework. LEADS Corporation Limited. You found me in internet: Blog: www.dotnetbd.wordpress.com LinkedIn: http:// bd.linkedin.com/pub/saifullah-azad/69/604/7a8 Facebook : https:// www.facebook.com/saifullah.azad. What Is It?.
E N D
MD. SAIFULLAH AL AZAD, Software Architect ADO.NET Entity Framework LEADS Corporation Limited You found me in internet: Blog: www.dotnetbd.wordpress.com LinkedIn: http://bd.linkedin.com/pub/saifullah-azad/69/604/7a8 Facebook: https://www.facebook.com/saifullah.azad
What Is It? • The ADO.NET Entity Framework is part of Microsoft’s next generation of .NET technologies. • It is intended to make it easier and more effective for object-oriented applications to work with data.
Architecture Visual Studio “Quadrant” Entity Framework Data Services ADO.NET “M”/EDM SQL Azure SQL Server … SQL Server Modeling Services
The Logical Data Model • Almost any business application today has to speak to a relational database. • This involves the usual suspects of tables with foreign keys, a smattering of views, and generally a gob of stored procedures.
The Object-Oriented Domain Model • Applications themselves are written in a completely different world. • The same data that lives in the relational database is represented entirely differently in the application.
The Result • The result of this “impedance mismatch” is that developers devote a lot of time and energy writing code to translate between how the database likes to see data and how the application likes to see data.
Other Ways to Address The Same Problem • Hibernate (Java) • Enterprise Objects Framework (Mac OS) • NHibernate (.NET) • LINQ to SQL (Visual Studio 2008) • And many, many, more …
The ADO.NET Entity Framework • The ADO.NET Entity Framework seeks to remedy the problem by providing a layer of abstraction between the logical data model and the application domain.
Why the Entity Model? • Closer to the application problem space • Better suited for object oriented programming • Supports Inheritance • Supports complex types • Relationships are more meaningful to the application
The “Stuff” in ADO.NET Entity Framework The tools and technology that developers will interact with when using the ADO.NET Entity Framework
Entity Data Model • A gob of XML that defines • Logical Data Tables, Views, Foreign Keys • Entity Objects that Map to the Logical Data • The Mapping Between the Two
Entity Data Model Designer • A Visual Studio Designer that protects developers from the XML that is the EDM
ObjectContext • A code-generated data context created from the Entity Data Model • Responsible for managing communication between the conceptual data model and the logical data model
Entities • Code-generated class definitions for objects defined in the EDM.
Getting the Data Out How do we get data out of the fancy Entity Data Model?
eSQL (Entity SQL) • A brand new SQL language to learn • Leverages the rich, object-oriented Entity Data Model • Inheritance • Collections • Complex Types • Literal Strings – No Compiler Checking • Questionable value in embedded SQL in code
Extensions Methods and String Predicates • Queries the object model created against the EDM • Still string-based. No compiler checking • An ugly mix of code and eSQL statements
LINQ to Entities • Full compiler checking. No wondering if the query is valid. • A fun new SQL-Like syntax • More OO-ish
What Can You Do? The power of the Entity Data Model contrasted to a logical data model of tables and stored procedures.
Combine Multiple Logical Tables into One Entity Database Tables Entity Data Model
Implement Inheritance Database Tables Entity Data Model
Other Fun Stuff • Implement Complex Types (e.g. Address) • Consume Conceptual Model with Reporting Services and other BI Tools • Create an EDM that talks to stored procedures • Use transactions, manage concurrency, cache execution plans
New in ADO.NET Entity Framework 4.0 • 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) Model-first development Automatic pluralization Foreign keys in models POCO class support Lazy loading T4 Code Generation Template customization IObjectSet Virtual SaveChanges ObjectStateManagercontrol
Provider Specific (PL/SQL) “SELECT * FROM CUSTOMERS” ADO.NET Today App Code ADO.NET Command Providers Execute SQL Server DataReader Oracle Oracle Customers Customers Customers ...
ADO.NET Entity Framework Conceptual Model Map Customers UKCustomer UKPremiumCustomer
Provider Agnostic (ESQL) “SELECT * FROM UKCUSTOMER” ADO.NET Entity Framework App Code ADO.NET Conceptual Model Map Entity Provider Command Execute DataReader Customers UKPremiumCustomer UKCustomer UKCustomer UKCustomer Providers* SQL Server Oracle Oracle ...
ADO.NET Entity Framework EF EF .NET Entity Provider (Entity SQL) Programming Model EF Entity Data Model (CSDL) Conceptual Model LINQ Reader Connection Command Entity Entity Object Relational Mapping relationship Mapping (MSL) V2.0 Store Model (SSDL) .NET Data Provider Store Reader Connection Adapter Command
Mapping Examples ( 1 – Splitting ) Mapping Store Entities Type=“G” Customers Good Customers CustomerId ID First FirstName Last LastName Type Bad Customers ID ForeName Type=“B” Surname
Mapping Examples ( 2 – TPH ) Store Mapping Entities Customer Customers CustomerId ID First FirstName Last LastName ? IsPremium Overdraft AccountManager PremiumCustomer Overdraft AccountManager * Framework also supports TPT
Mapping Examples ( 3 – View + SPs ) Store Mapping Entities UkCustomer ClientView1 CustomerId select c.id, c.name from customers c where c.country = ‘UK’ Name p_DeleteUkCustomer p_UpdateUkCustomer p_InsertUkCustomer