getting started with entity framework

17
Lushanthan S. getting started with Microsoft Entity Framework

Upload: lushanthan-sivaneasharajah

Post on 24-May-2015

3.820 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Getting started with entity framework

Lushanthan S.

getting started with Microsoft

Entity Framework

Page 2: Getting started with entity framework

Today’s Agenda Introduction

The Architecture

Entity Data Model

The Conceptual Model – .edmx file, exploring the classes

Demo LINQ to Entities Lazy Loading CRUD Stored Procedures

Shipped Products

Page 3: Getting started with entity framework

Intr

oduc

tion

Our life so far…All of us have worked on Data access!

Objects != Relational Data – “Impedance mismatch”

Powerful, but fragile and time consuming!

Languages C# SQL

Tools Visual Studio SQL Server

Paradigms Object Procedural

Common API ADO.NET

Page 4: Getting started with entity framework

Intr

oduc

tion

Legacy ADO.NETSample Code:

using (SqlConnection conn = new SqlConnection("<conn string>")) { conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "sp_StoredProc"; cmd.parameters.AddWithValue("@City", "Colombo");

using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.read()) { string name = rdr.GetString(0); string city = rdr.GetString(1); } } }

Loosely typed!

Page 5: Getting started with entity framework

What about microsoft giving this to us as a Product?

Yes, there comes Microsoft Entity Framework

Page 6: Getting started with entity framework

Intr

oduc

tion

History of Data Access in .Net

ADO.Net Inline SQL

Data Sets

Stored Procedures

ORM - Typed Data Sets, LINQ to SQL, EF1, EF4

Bridging the gap between objects and relational data!

Page 7: Getting started with entity framework

Intr

oduc

tion

What is Entity Framework?

Released in July 2008, EF is a data access framework from Microsoft that helps to bridge the gap between data structures and objects in your applications.

What does it really do?

It automatically, generates strongly-typed entity objects that can be

customized beyond 1-1 mapping generates mapping/plumbing code translates LINQ queries to database queries materializes objects from data store calls tracks changes, generating updates/inserts

Page 8: Getting started with entity framework

The

Arch

itect

ure

Under the hood

Page 9: Getting started with entity framework

The

Arch

itect

ure

Bird’s Eye View

Store

ADO.NET Data Provider(SqlClient, OracleClient)

Command

ConnectionReader

Adapter

Entity Framework

Conceptual Data Model

ADO.NET Entity Provider (entity client)

LINQ to Entities, Entity SQL, Query builder methods

Programming Model

Map

ping

Legacy ADO.NET does not go away!

Page 10: Getting started with entity framework

Entit

y D

ata

Mod

elEntity Data ModelSet of objects that describe structure of your business data and map to your underlying data store.

DatabaseSchema

EntityObjects

MappingStorage Model Conceptual Model

Database ServicesOOUI

Contained in Three XML sections stored in *.edmx file:

Page 11: Getting started with entity framework

The

Conc

eptu

al M

odel

The Conceptual Model

Page 12: Getting started with entity framework

Following sections will be covered

.

Demo

Exploring the conceptual model

Database First

Model First

LINQ to Entities

CRUD

Lazy Loading

Include()

Stored Procedures.

Page 13: Getting started with entity framework

Ship

ped

Prod

ucts

Shipped Products Entity Framework 1.0 (.NET 3.5 SP1/ VS 2008 SP1 )

Entity Framework 4.0 (.NET 4/ VS 2010 )• Model-First support• Foreign Keys in the conceptual Model• Lazy loading• Persistence-Ignorant Objects (POCO) support• Self-Tracking Entities

Entity Framework 4.1, 4.2, 4.3 (.NET 4/ VS 2010 )• Code-first Migration

Entity Framework 5.0 beta1, 2 (.NET 4.5 Beta/ VS 2011 Beta )• Enum support• Tabled valued functions support

Page 14: Getting started with entity framework

L2S Strongly typed LINQ access for RAD against SQL Server

onlySupport s only direct Table-Per-Type (1-to-1) mappingLimited out-of-the box support for complex scenarios

EF Designed for larger enterprise applicationsEnables complex mapping complex scenarios Tools and designer more robustSupports inheritance and many-to-many relationshipsSupports provider independence

Linq to SQL Vs Entity Framework

Rob Vettor

14

Page 15: Getting started with entity framework

? But wait… There’s More!

Page 16: Getting started with entity framework

POCO Entities

Entity SQL

T4 Templates

Code first Approach

Areas not covered

Rob Vettor

16

Page 17: Getting started with entity framework

Q & A Session

Microsoft

Entity Framework

The End