+ All Categories
Home > Documents > Entity Framework

Entity Framework

Date post: 22-Feb-2016
Category:
Upload: marv
View: 52 times
Download: 0 times
Share this document with a friend
Description:
Entity Framework. Object Relational Mapping – ORM Entity Framework. ORM?. Objects vs. Relations. Relational. Object-Relational Impedance Mismatch. Object-Oriented. Based on proven software engineering principles. Entry point is behaviour - PowerPoint PPT Presentation
Popular Tags:
17
C# kursus Rohde & Schwarz 1 Object Relational Mapping – ORM Entity Framework Entity Framework
Transcript
Page 1: Entity Framework

1C# kursus Rohde & Schwarz

Object Relational Mapping – ORMEntity Framework

Entity Framework

Page 2: Entity Framework

2

ORM?

C# kursus Rohde & Schwarz

Page 3: Entity Framework

C# kursus Rohde & Schwarz 3

Objects vs. Relations

Page 4: Entity Framework

C# kursus Rohde & Schwarz 4

Object-Relational Impedance Mismatch

Object-Oriented RelationalBased on proven software engineering principles.Entry point is behaviourObject collections and associations derived from graph theory

Based on proven mathematical principles.Entry point is dataData collections and associations derived from set theory

Page 5: Entity Framework

C# kursus Rohde & Schwarz 5

A Physical Data Model

Page 6: Entity Framework

C# kursus Rohde & Schwarz 6

A Class Model

Page 7: Entity Framework

C# kursus Rohde & Schwarz 7

Differences

Physical Data Model Class Model

Page 8: Entity Framework

C# kursus Rohde & Schwarz 8

Benefits Of O/R Mapping

Clean OO designHiding the relational model specifics lets the object model be more cleanly analyzed and applied.

ProductivitySimpler code as the object model is free from persistence constraints. Developers can navigate object hierarchies, etc.

Separation of concerns and specializationLet the DB people worry about DB structure and the Object people worry about their OO models.

Time savingsThe O/R mapping layer saves you from writing the code to persist and retrieve objects. O/R mapping tool vendors claim 20-30% reduction in the code that needs to be written. Writing less code also means less testing.

Page 9: Entity Framework

C# kursus Rohde & Schwarz 9

Drawbacks Of O/R Mapping

Usually commit the "Needless Repetition" deadly sin (a.k.a. DRY – "Don't Repeat Yourself“)

The table structure as well as their relations are stored both in the DB and in the mapping files used by the O/R mapper

Writing mapping files is a huge taskNeeds to be updated every time the database layout is changed

QueriesLimited query capabilities…… or performance problems on complicated queries

Some O/R mappers implement caches, lazy initialization, batch modes etc. to help avoid the performance problems

Page 10: Entity Framework

C# kursus Rohde & Schwarz 10

ENTITY FRAMEWORK

Page 11: Entity Framework

C# kursus Rohde & Schwarz 11

Entity Framework

What is Entity Framework?Entity Framework (EF) is an object-relational mapper that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write.

http://msdn.microsoft.com/en-us/data/ef.aspx

Page 12: Entity Framework

C# kursus Rohde & Schwarz 12

Supported Databases

MS SQL ServerMySQLSQLiteOracleFirebirdPostgreSQL... and more

Page 13: Entity Framework

C# kursus Rohde & Schwarz 13

Getting Started

EF supports four development workflows:http://msdn.microsoft.com/en-us/data/jj590134

Find out which fits your conditions:http://msdn.microsoft.com/en-us/data/ee712907

Page 14: Entity Framework

C# kursus Rohde & Schwarz 14

Installation

Pre installed with Visual Studio 2012Can be installed with NuGet in Visual Studio 2010

You might need to install NuGet first...

Page 15: Entity Framework

C# kursus Rohde & Schwarz 15

Using Entity Framework

Create a mapping of your databaseEntity Data Model (Model First)

Database migrations not possible (yet)Plain Old CLR Objects (POCO) (Code First)

Database migrations possible

Page 16: Entity Framework

C# kursus Rohde & Schwarz 16

Using Entity Framework

Connect through a sub class of DbContext

Make queries using LINQ

Page 17: Entity Framework

C# kursus Rohde & Schwarz 17

Demo


Recommended