Back to: Entity Framework Tutorials For Begineers and Professionals
Model Browser in Entity Framework:
In this article, I am going to discuss the Model Browser in Entity Framework Database First Approach. Please read our previous article where we discussed the Entity Data Model (EDM) in detail. We are going to work with the same example that we created in our introduction to Entity Framework Database First Approach article. Please read our introduction to Entity Framework Database First article before proceeding to this article.
Model Browser in Entity Framework
The Visual Designer of the Entity Data Model does not display all the objects it creates. It only displays entities that are mapped to the database tables and views. As we know, we have created some stored procedures in our database. And while creating the Entity Data Model we have also included those stored procedures. But if you look at the Visual Designer of the Entity Data Model, then you will not find those stored procedures as shown in the below image. Here, you can see only the Entities which are mapped to the database tables and views.
The Model Browser in Entity Framework gives you information about all the Objects (Classes) and Functions (Stored Procedures are created as Functions by Entity Framework) EDM has created.
What is Model Browser in Entity Framework?
The Model Browser in Entity Framework is a Visual Studio tool that is integrated with ADO.NET Entity Data Model Designer (Entity Designer). It provides the Conceptual and Storage Models tree view that is defined in a .EDMX file. The Model Browser groups information into two nodes.
Model Browser in Entity Framework gives all the information about all the objects and functions created by the EDM. In order to open the Model Browser, right-click the empty surface on the EDM designer and select Model Browser from the context menu as shown in the below image.
The Model Browser will appear in the area where you normally find Solution Explorer and Properties. The Entity Framework Model Browser contains all the information about the EDM, its Conceptual Model, Storage Model, and Mapping Information, as shown in the below image.
The Second node shows the Conceptual Model. By expanding the child nodes, you can view all entity types i.e. Classes and Associations i.e. Foreign Keys, Complex Types i.e. the result set of stored procedures, and functions i.e. the corresponding stored procedures. The Conceptual Schema Model also called as Conceptual Schema Definition Layer (CSDL) is the real entity model, and using this entity model we are going to write our queries. That means based on the database tables, views, stored procedures, primary key, and foreign keys relationship between the database tables, this Conceptual Schema Definition Layer (CSDL) creates the corresponding classes and functions.
The Third node shows the target Database Model. By expanding the child nodes, you can see which parts of the database tables, views, and stored procedures have been imported to the model. The Storage Schema Model also called Storage Schema Definition Layer (SSDL) represents the schematic representation of the backend data store. That means what are the database tables, views, stored procedures, what are primary keys, and the foreign key relationship between the database tables, that you have included while creating the EDMX file, all those information is going to represent by this Storage Schema Definition Layer (SSDL) Model. So, it is all about the backend database.
Understanding the Different Elements of Model Browser in Entity Framework:
The Entity Framework Model Browser contains all the information about the EDM, its Conceptual Model, Storage Model, and Mapping Information, as shown in the below image.
As you can see in the above image, the Model Browser contains the following objects:
- Diagrams: The Model Browser contains the Visual Diagrams of the EDM. You can see the default visual diagram created by EDM i.e. Diagram1. It is also possible to create multiple Visual diagrams for one EDM if the application has a large number of entities
- Entity Types: The Entity Types list all the class types which are mapped to the database tables.
- Complex Types: Complex types are the classes that are generated by EDM to contain the result of stored procedures, table-valued functions, etc. These complex types are customized classes for different purposes.
- Enum Types: Enum Types lists all the entities which are used as Enum in the entity framework.
- Associations: Associations lists all foreign key relationship between the entity types.
- Function Imports: Function Imports lists all the functions which will be mapped to stored procedures, table-valued functions, etc. Stored procedures and table-valued functions will be used as functions and not as entities in Entity Framework.
- EF_Demo_DBModel.Store: It represents the database schema (i.e. SSDL) i.e. the database tables, views, functions, stored procedures, and the primary key and foreign key relationships between the tables. If you expand the child nodes you will see the following.
Where is Entity Table Mapping in EDM Designer View?
In the Model Browser, you can see and view the Conceptual Model (CSDL) and Storage Model (SSDL), but you can not see the Mapping Model (C-S Mapping). Then how you can view the C-S Mapping? Let us proceed and see how to view the Entity -Table Mapping in EDM Designer View in Entity Framework.
Entity-Table (C-S) Mapping in EDM Designer View
The point that you need to remember is each Entity in EDM is mapped with the database table. We have already seen this Mapping using the EDM XML View. You can also check the Entity-Table Mapping using the EDM Designer View. To check the Entity-Table Mapping, right-click on any Entity in the EDM designer and then select Table Mapping. Let’s see the Student Entity Mapping. So, right-click on the Student Entity in the EDM Designer View and then select Table Mapping which shows the following.
As you can see in the above image, the Student Entity is Mapped with the Student database table and each property of the Student Entity is Mapped with Student Database table columns. If you change any property name of the Entity from EDM Designer View, then the table mapping would reflect that change automatically. You can also Map a property with a different column of the database table. But we generally never do such kind of changes.
In the next article, I am going to discuss the DbContext Class in Entity Framework Database First Approach. In this article, I try to explain the Model Browser in Entity Framework Database First Approach and I hope you enjoyed the Model Browser in Entity Framework article. Please give your valuable feedback and suggestions about this article.