Presentation is loading. Please wait.

Presentation is loading. Please wait.

ADO.NET Entity Framework Marcus Tillett

Similar presentations


Presentation on theme: "ADO.NET Entity Framework Marcus Tillett"— Presentation transcript:

1 ADO.NET Entity Framework Marcus Tillett
0:21 My name is Marcus Tillett And I’m a Senior Software Architect at Dot Net Solutions, Based here in Windsor I’m going to talk about the ADO.NET Entity Framework Part of .NET 3.5, currently in beta Next: First, I want to have a brief look at the Entity framework And look at where it is applicable

2 Overview Introduction to ADO.NET Entity Framework
Using the Visual Studio Tools 0:42 First, I want to have a brief look at the Entity framework. And look at where it is applicable Then, taking an example I want to look how you would do this using the tools in Visual Studio. My title refer to OO Architect vs. Data Architect. Next: This is because My requirement is to take advantage OO concepts, such as inheritance, when writing applications but to persist the data in a relational database

3 OO Architect vs. Data Architect
22/09/2018 2:27 PM OO Architect vs. Data Architect Requirement to use an OO language to manipulate entities persist these in a relational database Impedance mismatch 1:03 My aim is to take advantage OO concepts, such as inheritance, when writing applications but to persist the data in a relational database Impedance mismatch is a broad term. Here I am using it to refer to the fact that relational databases are not good at storing OO concepts This is where the ADO.NET entity framework steps in. Next: What the ADO.NET entity framework does is provide a level of abstraction from the data. 3 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

4 ADO.NET Entity Framework
1:24 What the ADO.NET entity framework does is provide a level of abstraction from the data. Shown in RED at the BOTTOM And give an API to manage the manipulate the entities it provides This is a diagram of the framework and I going to briefly discuss each part of the model Next: First, the logical model The logical model is a representation of the database schema.

5 Logical Model Logical layer stored as schema definition language (SSDL) 1:45 First, the logical model The logical model is a representation of the database schema. The logical model might contain a representation of each table in the database It can also represent views

6 Conceptual Model Conceptual model is an Entity Data Model (EDM) schema stored using conceptual schema definition language (CSDL) 2:06 The conceptual model contains entities. So here in the conceptual model I have 2 entities. These are the class that are exposed to develop against and is the API for the entity framework Next: Most importantly is the mapping layer.

7 Mapping A mapping specification uses mapping specification language (MSL) to connect the types declared in CSDL to the database metadata declared in SSDL 2:27 Most importantly is the mapping layer. This stores the mappings between the entities in the conceptual model against the tables in the logical model This is a specification language, as are all the parts of the model defined in separate definition languages This is stored in XML, again this applied to the other part of the model

8 MSL Mapping 2:48 This is a snippet of the XML schema for the MSL.
The mapping definition language. This shows the mapping between an entity Person and the database representation of this entity. And maps a name property on the entity to a Name column in the database table Next: Now with the entity model, I can create business logic on top of the conceptual model.

9 Business Logic 3:09 Now with the entity model, I can create business logic on top of the conceptual model. My business object can interact with any number of the entities and not directly with the database To use the entity framework, Now I want to look at an example. This example is part of the impedance mismatch that I mentioned earlier. In this example I want to look at an inheritance structure.

10 Example: Required Entity Model
22/09/2018 2:27 PM Example: Required Entity Model 3:30 Now I have my entity framework, I want to look at storing this class structure in a relational database. I have 4 classes in a very basic inheritance structure: Person, Employee, Broker and Applicant. There are a number of technical of doing this. Next: Table per type 10 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

11 22/09/2018 2:27 PM Table per Type 3:51 I have chosen to use table per type, each class has a corresponding table in the data model. Normalised There is no duplication of data between these tables, for instance the Name column only appears on the Person table Next: Viewed on top of the entity model framework. 11 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

12 Table per Type 4:12 Viewed on top of the entity model framework.
22/09/2018 2:27 PM Table per Type 4:12 Viewed on top of the entity model framework. Each one of my classes is represented in the conception model These map to the same number of tables in my logical model The mapping being handled by the mapping layer. What I can do is reserve engineer these entities from my data model 12 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

13 Visual Studio Designer
22/09/2018 2:27 PM Visual Studio Designer 4:33 If I reverse engineer my entity model from the database, I produces this. I has not understand that I am trying to store an inheritance structure in my database. This is fair enough Next: I need to do some extra work 13 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

14 22/09/2018 2:27 PM Remove Relation 4:54 I have to do a bit of work to finish building my entity model. From my entity model, I need to delete the relationships between the class. This is from the entity model, these constraints are still in the database. I also need to remove the key from the sub classes. Next: Then I can add by inheritance in. 14 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

15 22/09/2018 2:27 PM Adding Inheritance 5:15 I can now add in the inheritance relationship for each of the sub classes. Here I am adding the Person as a base class for the Employee Next: Nearly done, but most importantly I need to create the mappings 15 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

16 Mapping Entities 5:36 For each of the classes in the entity model.
22/09/2018 2:27 PM Mapping Entities 5:36 For each of the classes in the entity model. I need to map that entity to the table in the database. Here I am mapping the Employee table to the Employee entity The Id is inherited from the super class. So I can map it to the primary key in the database Next: That’s it I have my entities. I can now use them 16 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

17 Using the Entities 5:57 Now I have build my entities, I can use them.
22/09/2018 2:27 PM Using the Entities 5:57 Now I have build my entities, I can use them. I might write some code that is something like this. Here I can creating a broker, saving and then fetching from the entity framework. All without dealing with database objects. Next: The last thing I want to show is that I can evolve my data model and therefore my logical model without changing my entities. 17 © 2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

18 Table per Hierarchy 6:18 I could store my whole hierarchy in a single table. In effect, all I need to do is update the model and provide the new mappings. But it requires a little more work. Next: In summary The entity framework provides a separation between the classes that are developed against and the tables in the database.

19 Summary ADO.NET Entity Framework provides a separation between the data and the entity Supports different inheritance modelling patterns Enables refactoring of data model 6:39 In summary The entity framework provides a separation between the classes that are developed against and the tables in the database. It supports different way to store inheritance structures Lastly, as I have shown always for a level of refactoring of the data model without changing the API

20 Summary http://www.vistasquad.co.uk
More information 6:59 Finally, a plug for vista squad a free Microsoft sponsor user group. I’ll be speaking there soon a little more in depth about the ADO.NET entity framework. Thank you for listening.


Download ppt "ADO.NET Entity Framework Marcus Tillett"

Similar presentations


Ads by Google