Top Banner
MD. SAIFULLAH AL AZAD, Software Architect LEADS Corporation Limited 6/17/22 ADO.NET ENTITY FRAMEWORK 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
33

ADO.NET Entity Framework

Feb 25, 2016

Download

Documents

ayasha

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?. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ADO.NET Entity Framework

MD. SAIFULLAH AL AZAD, Software Architect LEADS Corporation Limited

April 22, 2023

ADO.NET ENTITY FRAMEWORK

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

Page 2: ADO.NET Entity Framework

What Is It?

Visual Studio 2010.NET 4.0LINQEntity 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.

Page 3: ADO.NET Entity Framework

SQLServer

SQLAzure

Visual Studio “Quadrant”

SQL Server Modeling Services

Entity Framework

ADO.NET “M”/EDM

Data Services

Architecture

Page 4: ADO.NET Entity Framework

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.

Tables

Views

Stored Procedures

Foreign Key Relationships

Page 5: ADO.NET Entity Framework

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.

Page 6: ADO.NET Entity Framework

The ResultLogical 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.

Page 7: ADO.NET Entity Framework

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 …

Page 8: ADO.NET Entity Framework

The ADO.NET Entity FrameworkLogical 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.

Page 9: ADO.NET Entity Framework

Why the Entity Model?Logical 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

Page 10: ADO.NET Entity Framework

The “Stuff” in ADO.NET Entity FrameworkThe tools and technology that developers will interact with

when using the ADO.NET Entity Framework

Page 11: 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

Page 12: ADO.NET Entity Framework

Entity Data Model Designer A Visual Studio

Designer that protects developers from the XML that is the EDM

Page 13: ADO.NET Entity Framework

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

Page 14: ADO.NET Entity Framework

Entities Code-generated

class definitions for objects defined in the EDM.

Page 15: ADO.NET Entity Framework

Getting the Data OutHow do we get data out of the fancy Entity Data Model?

Page 16: ADO.NET Entity Framework

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

Page 17: ADO.NET Entity Framework

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

Page 18: ADO.NET Entity Framework

LINQ to Entities Full compiler

checking. No wondering if the query is valid.

A fun new SQL-Like syntax

More OO-ish

Page 19: ADO.NET Entity Framework

What Can You Do?The power of the Entity Data Model contrasted to a logical

data model of tables and stored procedures.

Page 20: ADO.NET Entity Framework

Combine Multiple Logical Tables into One EntityDatabase Tables Entity Data Model

Page 21: ADO.NET Entity Framework

Implement InheritanceDatabase Tables Entity Data Model

Page 22: ADO.NET Entity Framework

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

Page 23: ADO.NET Entity Framework

Manipulate Data By Manipulating ObjectsDatabase Result Desired EDM Object ManipulationINSERT ROW Create new object

Add object to EDM ContextUpdate Context

DELETE ROW Get instance of object from EDM ContextAsk Context to remove the objectUpdate Context

UPDATE ROW Get instance of object from EDM ContextUpdate objectUpdate Context

Page 24: ADO.NET Entity Framework

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)

Page 25: ADO.NET Entity Framework

App Code

Customers

ADO.NET

ProvidersSQL Server

Oracle

...

DataReader

Customers

Oracle

Command

Execute

Provider Specific (PL/SQL)

“SELECT * FROM CUSTOMERS”Customers

ADO.NET Today

Page 26: ADO.NET Entity Framework

Customers

Conceptual Model

UKCustomer

UKPremiumCustomer

Map

ADO.NET Entity Framework

Page 27: ADO.NET Entity Framework

App Code

Customers

ADO.NET

Providers*SQL Server

Oracle

...

Oracle

EntityProvider

DataReader

UKCustomer

Command

Execute

Conceptual Model

UKCustomer

UKPremiumCustomer

Map

Provider Agnostic (ESQL)

“SELECT * FROM UKCUSTOMER”

UKCustomer

ADO.NET Entity Framework

Page 28: ADO.NET Entity Framework

.NET Entity Provider (Entity SQL)

Command

ConnectionReader

EF

Store

.NET Data Provider

V2.0

Command

ConnectionReader

Adapter

EF

Conceptual Model

Entity Entityrelationship

Mapping (MSL)

EFProgramming Model

Object Relational Mapping

LINQ

ADO.NET Entity Framework

Page 29: ADO.NET Entity Framework

Store

Good Customers

IDFirstNameLastName

Bad Customers

IDForeNameSurname

Customers

CustomerIdFirstLastType

EntitiesMapping

Type=“G”

Type=“B”

Mapping Examples ( 1 – Splitting )

Page 30: ADO.NET Entity Framework

Store

Customer

CustomerId

First

Last

EntitiesMapping

CustomersID

FirstName

LastName

IsPremium

Overdraft

AccountManager PremiumCustomer

Overdraft

AccountManager

?

* Framework also supports TPT

Mapping Examples ( 2 – TPH )

Page 31: ADO.NET Entity Framework

Store

UkCustomer

CustomerIdName

EntitiesMapping

ClientView1select c.id, c.namefrom customers cwhere c.country = ‘UK’

p_DeleteUkCustomer

p_UpdateUkCustomer

p_InsertUkCustomer

Mapping Examples ( 3 – View + SPs )

Page 32: ADO.NET Entity Framework

Any Question

Page 33: ADO.NET Entity Framework