1 / 69

Object Relational mapping

System Design. Object Relational mapping. Introduction. The contribution of technology ORM. The use of technologies of ORM brings many improvements in the development of applications: Simplification of the Code, only "talking object" from the highest to the lowest layer.

alford
Download Presentation

Object Relational mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. System Design Object Relational mapping

  2. Introduction

  3. The contribution of technology ORM • The use of technologies of ORM brings many improvements in the development of applications: • Simplification of the Code, only "talking object" from the highest to the lowest layer. • Increase maintainability, there is more code SQL to maintain within the object code. • Increase portability, the database is hidden it is possible to move from one DBMS to another (within the support of ORM selected).

  4. Different ORM Technologies the ORM is a concept and thus different implementations with more or less features will be found. For example • Entity Framework in .Net • Hibernate in Java, Hibernate tutorial • Java Persistence API, Introduction to the Java Persistence API • Ruby has an ORM framework check Toolbox

  5. The process of ORM • Mapping classes. • Mapping attributes. • Mapping relationships. • Inheritance.

  6. 1. Mapping classes • In general, classes map to tables in one-to-one mapping. • In some cases, multiple classes can map to a single table, e.g., inheritance. • <<Class model>> <<Data Model>>

  7. 2. Mapping attributes. • The most straightforward mapping. • Simple types are common between object paradigm and relational models. • <<Class model>> <<Data Model>>

  8. 3. Mapping relationships • Use a Foreign Key Mapping to map a single-valued field. • Use a Foreign Key Mapping to map a collection field.

  9. 3. Mapping relationships • Use an Association Table Mapping to map a many-to-many association.

  10. 4. Mapping Inheritance • Map the entire class hierarchy to a single table (TPH) • Map each concrete class to its own table (TPC) • Map each class to its own table (TPT)

  11. 4. Mapping Inheritance Map the entire class hierarchy to a single table

  12. 4. Mapping Inheritance Map each concrete class to its own table

  13. 4. Mapping Inheritance Map each concrete class to its own table

  14. Some Guidelines • Every UML Class may become a Table. • Every UML Attribute in Class becomes a Column in a Table. • Every UML Attribute Type becomes a Column Type using a Type Transformation Table. • Every Nullable UML Attribute becomes a Nullable Column, otherwise NOT NULL constraint. • If UML Attribute has Initializer, add DEFAULT value to Column. • For Classes with no generalization and implicit identity, create primary key as sequence id .

  15. Some Guidelines • For Sub-Classes, add the key of each parent class to the Primary Key of the Table and to a Foreign Key constraint. • For Association Classes, add the primary key from each role-playing table to PRIMARY KEY constraint and FOREIGN KEY constraint. • Create PRIMARY KEY for composite aggregations with FOREIGN KEY to aggregating tables and add additional column for PRIMARY KEY. • Create Tables for many-to-many associations with no association classes. • Create PRIMARY KEY, FOREIGN KEY constraints from keys of role-playing tables in many-to-many associations.

  16. Entity Framework

  17. 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. • Its project independent. It can be added to any .Net project, eg. Web application, windows forms ..etc.

  18. Steps: Adding Entity Data Model

  19. Step: choose model contents

  20. Constructing the Entity Framework • Based ON Model [Model First] • Code First

  21. Entity Framework Based On THE Model

  22. Based On The Model • For Inheritance mapping : • Each on its own table • Single table Not support concrete classes mapping

  23. Step: choose model contents

  24. Based on the Model Each on its own table

  25. Create Model

  26. Create Model: Adding entities and relations

  27. Validate the model

  28. Generate Database from Model

  29. Generate Database from Model: set connection

  30. Generate Database from Model: set connection

  31. Generate Database from Model: set connection

  32. Generate Database from Model: set connection

  33. Generate Database from Model: SQL Script

  34. Generate Database from Model: Running SQL Script

  35. Generate Database from Model: Running SQL Script

  36. Created Database: All in its own table

  37. Created classes

  38. Created classes

  39. Based on the Model Single table

  40. Add Staff Table To Contain All Fields

  41. Generate Database

  42. Created Database

  43. To apply single table

  44. Add the sub Classes: Change mapping detailed

  45. Change mapping detailed: Teaching Staff

  46. Change mapping detailed: Teaching Staff-Add condition

  47. Change mapping detailed: Administrator

  48. Created Classes

  49. Entity Framework Based On Code first

  50. Based On Code First • For Inheritance mapping : • Each on its own table • Single table • concrete classes

More Related