getting started with entity framework
TRANSCRIPT
Lushanthan S.
getting started with Microsoft
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
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
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!
What about microsoft giving this to us as a Product?
Yes, there comes Microsoft 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!
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
The
Arch
itect
ure
Under the hood
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!
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:
The
Conc
eptu
al M
odel
The Conceptual Model
Following sections will be covered
.
Demo
Exploring the conceptual model
Database First
Model First
LINQ to Entities
CRUD
Lazy Loading
Include()
Stored Procedures.
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
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
? But wait… There’s More!
POCO Entities
Entity SQL
T4 Templates
Code first Approach
Areas not covered
Rob Vettor
16
Q & A Session
Microsoft
Entity Framework
The End