Entity Framework

leathermumpsimusΛογισμικό & κατασκευή λογ/κού

13 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

57 εμφανίσεις

Local Touch – Global Reach
www.wright.edu/idse
www.us.sogeti.com
Entity Framework
Local Touch – Global Reach
2
www.wright.edu/idse
www.us.sogeti.com
Features
 Abstracts conceptual schema from physical schema
– ORM (Object Relational Mapping)
 Approach
– Database first
– Model first (upcoming)
 Database support
– MS SQL, Others through third party
 Not POCO (Plain Old CLR Object) by default
– EntityObject base class
Local Touch – Global Reach
3
www.wright.edu/idse
www.us.sogeti.com
Design surface
Local Touch – Global Reach
4
www.wright.edu/idse
www.us.sogeti.com
Models
 Conceptual Model
– Domain Model
– Conceptual Schema Definition Language (CSDL)
 Storage Model
– Store Schema Definition Language (SSDL)
 Mappings

Mapping Specification Language (MSL)
Local Touch – Global Reach
5
www.wright.edu/idse
www.us.sogeti.com
Entity Data Model
 Entities
 Relationships
– Navigation properties
Local Touch – Global Reach
6
www.wright.edu/idse
www.us.sogeti.com
Architecture
Local Touch – Global Reach
7
www.wright.edu/idse
www.us.sogeti.com
Context
 Object Context
 Connection to underlying data source
 Change tracking
 Identity resolution
Local Touch – Global Reach
8
www.wright.edu/idse
www.us.sogeti.com
ObjectSet
 Generated property on Context

Represents one entity (table)
Local Touch – Global Reach
9
www.wright.edu/idse
www.us.sogeti.com
Querying Data
 LINQ to Entities
 Entity SQL
 Query Builder Methods
Local Touch – Global Reach
10
www.wright.edu/idse
www.us.sogeti.com
LINQ to Entities
using ( var context = new AdventureWorks2008Entities() ) {
var query = from p in context.People
where p.ID == 2
select p;
Person person = query.FirstOrDefault();
}
Local Touch – Global Reach
11
www.wright.edu/idse
www.us.sogeti.com
Loading related entities
 Lazy Loading
 Eager Loading
 Explicit Loading
Local Touch – Global Reach
12
www.wright.edu/idse
www.us.sogeti.com
CRUD
 ObjectSet
– CreateObject
– AddObject
– DeleteObject
– SaveChanges
Local Touch – Global Reach
13
www.wright.edu/idse
www.us.sogeti.com
Modification Functions
 Stored procedures to insert, update, delete
 Used instead of generated commands
 DBAs may like this approach
Local Touch – Global Reach
14
www.wright.edu/idse
www.us.sogeti.com
Mapping class hierarchies
 Approaches
– Table per hierarchy

Table per type
Local Touch – Global Reach
15
www.wright.edu/idse
www.us.sogeti.com
Resources
 Web
– Microsoft MSDN
http://msdn.microsoft.com/en-us/library/bb399572.aspx
 Books
– Entity Framework 4.0 Recipes: A Problem-Solution
Approach, Larry Tenny, Zeeshan Hirani