Download presentation
Presentation is loading. Please wait.
1
ADO.NET Entity Framework
September 22, 2018September 22, 2018 MD. SAIFULLAH AL AZAD, Software Architect LEADS Corporation Limited You found me in internet: Blog: LinkedIn: Facebook:
2
What Is It? Visual Studio 2010 .NET 4.0 LINQ Entity Framework 4.2 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.
3
SQL Server Modeling Services
Architecture Visual Studio “Quadrant” Data Services Entity Framework ADO.NET “M”/EDM SQL Azure SQL Server … SQL Server Modeling Services
4
The Logical Data Model Tables Views Stored Procedures Foreign Key Relationships 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.
5
The Object-Oriented Domain Model
Objects Behavior Properties Inheritance Complex Types 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.
6
The Result Logical Data Model Lots of Custom Code Application Domain 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.
7
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 …
8
The ADO.NET Entity Framework
Logical Data Model Entity Data Model Less Custom Code Application Domain 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.
9
Why the Entity Model? Logical Data Model Entity Data Model
Tables Rows Foreign Keys Entity Data Model Entity Sets Entities Relationships Closer to the application problem space Better suited for object oriented programming Supports Inheritance Supports complex types Relationships are more meaningful to the application
10
The “Stuff” in ADO.NET Entity Framework
The tools and technology that developers will interact with when using the ADO.NET Entity Framework
11
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
12
Entity Data Model Designer
A Visual Studio Designer that protects developers from the XML that is the EDM
13
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
14
Entities Code-generated class definitions for objects defined in the EDM.
15
Getting the Data Out How do we get data out of the fancy Entity Data Model?
16
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
17
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
18
LINQ to Entities Full compiler checking. No wondering if the query is valid. A fun new SQL-Like syntax More OO-ish
19
What Can You Do? The power of the Entity Data Model contrasted to a logical data model of tables and stored procedures.
20
Combine Multiple Logical Tables into One Entity
Database Tables Entity Data Model
21
Implement Inheritance
Database Tables Entity Data Model
22
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
23
Manipulate Data By Manipulating Objects
Database Result Desired EDM Object Manipulation INSERT ROW Create new object Add object to EDM Context Update Context DELETE ROW Get instance of object from EDM Context Ask Context to remove the object UPDATE ROW Update object
24
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)
25
ADO.NET Today App Code ADO.NET Providers Provider Specific (PL/SQL)
“SELECT * FROM CUSTOMERS” Customers ADO.NET Today App Code ADO.NET Customers Command Providers Execute SQL Server Oracle Oracle ... DataReader Customers
26
ADO.NET Entity Framework
Conceptual Model UKCustomer UKPremiumCustomer Customers Map
27
ADO.NET Entity Framework
Provider Agnostic (ESQL) “SELECT * FROM UKCUSTOMER” UKCustomer ADO.NET Entity Framework App Code ADO.NET Conceptual Model UKCustomer UKPremiumCustomer Map Entity Provider Customers Command Execute Providers* DataReader UKCustomer SQL Server Oracle Oracle ...
28
ADO.NET Entity Framework
.NET Entity Provider (Entity SQL) Command Connection Reader EF EF Conceptual Model Entity relationship EF Programming Model Object Relational Mapping LINQ Store Model (SSDL) Entity Data Model (CSDL) Mapping (MSL) Store .NET Data Provider V2.0 Command Connection Reader Adapter
29
Mapping Examples ( 1 – Splitting )
Store Good Customers ID FirstName LastName Bad Customers ForeName Surname Mapping Customers CustomerId First Last Type Entities Type=“G” Type=“B”
30
Mapping Examples ( 2 – TPH )
Store Mapping Entities Customers ID FirstName LastName IsPremium Overdraft AccountManager Customer CustomerId First Last ? PremiumCustomer Overdraft AccountManager * Framework also supports TPT
31
Mapping Examples ( 3 – View + SPs )
Store Mapping Entities ClientView1 select c.id, c.name from customers c where c.country = ‘UK’ UkCustomer CustomerId Name p_DeleteUkCustomer p_UpdateUkCustomer p_InsertUkCustomer
32
Any Question
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.