Download presentation
Published byCamille Chipps Modified over 9 years ago
1
Object Relational Mapping – ORM Entity Framework
C# kursus Rohde & Schwarz
2
ORM? C# kursus Rohde & Schwarz
3
Objects vs. Relations C# kursus Rohde & Schwarz
4
Object-Relational Impedance Mismatch
Object-Oriented Relational Based on proven software engineering principles. Entry point is behaviour Object collections and associations derived from graph theory Based on proven mathematical principles. Entry point is data Data collections and associations derived from set theory C# kursus Rohde & Schwarz
5
A Physical Data Model Both diagrams depict structure, the PDM shows four database tables and the relationships between them whereas the UML class diagram shows four classes and their corresponding relationships. Both diagrams depict data, the PDM shows the columns within the tables and the class model the attributes of the classes. Both diagrams also depict behavior, the Customer table of Figure 1 includes a delete trigger and the Customer class of Figure 2 includes two operations. C# kursus Rohde & Schwarz
6
A Class Model Both diagrams depict structure, the PDM shows four database tables and the relationships between them whereas the UML class diagram shows four classes and their corresponding relationships. Both diagrams depict data, the PDM shows the columns within the tables and the class model the attributes of the classes. Both diagrams also depict behavior, the Customer table of Figure 1 includes a delete trigger and the Customer class of Figure 2 includes two operations. C# kursus Rohde & Schwarz
7
Differences Physical Data Model Class Model
Differences in your modeling approaches will result in subtle differences between your object schema and your data schema: By considering both data and behavior in the class diagram the modeler created a different structure than in the data model that only considered data Data normalization in data modeling versus class normalization in class modeling The application of data analysis patterns (Hay 1996) versus object-oriented analysis patterns (Fowler 1997; Ambler 1997) and design patterns (Gamma et. al. 1995) There are differences in the types of relationships that each model supports, with class diagrams being slightly more robust than physical data models for relational databases. This is because of the inherent nature of the technologies. For example, you see that there is a many-to-many relationship between Customer and Address in Figure 2, a relationship that was resolved in Figure 1 via the CustomerAddress associative table. Object technology natively supports this type of relationship but relational databases do not, which is why the associative table was introduced. C# kursus Rohde & Schwarz
8
Benefits Of O/R Mapping
Clean OO design Hiding the relational model specifics lets the object model be more cleanly analyzed and applied. Productivity Simpler code as the object model is free from persistence constraints. Developers can navigate object hierarchies, etc. Separation of concerns and specialization Let the DB people worry about DB structure and the Object people worry about their OO models. Time savings The 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. 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 task Needs to be updated every time the database layout is changed Queries Limited 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 C# kursus Rohde & Schwarz
10
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. C# kursus Rohde & Schwarz
12
Supported Databases MS SQL Server MySQL SQLite Oracle Firebird
PostgreSQL ... and more C# kursus Rohde & Schwarz
13
Getting Started EF supports four development workflows: Find out which fits your conditions: C# kursus Rohde & Schwarz
14
Installation Pre installed with Visual Studio 2012
Can be installed with NuGet in Visual Studio 2010 You might need to install NuGet first... C# kursus Rohde & Schwarz
15
Using Entity Framework
Create a mapping of your database Entity Data Model (Model First) Database migrations not possible (yet) Plain Old CLR Objects (POCO) (Code First) Database migrations possible C# kursus Rohde & Schwarz
16
Using Entity Framework
Connect through a sub class of DbContext Make queries using LINQ C# kursus Rohde & Schwarz
17
Demo C# kursus Rohde & Schwarz
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.