The ADO.NET Entity Data Model designer provide a Graphical User Interface tool to design the Entity Framework Models. We'll create and modify the entities, associations and inheritance relationships with the Entity Designer and we can also validate the model.
In that context, we'll today work on this session to create an Entity Model and use it in the application.
So, let's proceed with the following sections:
Create an ASP.NET Web Application in the MVC Project Template in Visual Studio 2013.
Working with Entity Model
Step 1: Just right-click on the Models folder to add an ADO.NET Entity Data Model named College.
Step 2: In the next wizard, select "Entity Model".
Step 3: The designer opens a blank model in which we add the entities. Just right-click on the designer to open "Properties".
Step 4: Set the Entity Container Name to CollegeDbContext as shown below:
Step 5: Right-click on "Design" then select "Add New" -> "Entity...".
Step 6: In the next wizard enter the entity name as College and CollegeId as the key column name and click "OK".
Step 7: Right-click on Entity to add a Scalar Property to it.
Step 8: Create the Name property also. Now add an another entity name Student and do the same as done above.
Step 9: Now right-click on design then select "Add New" -> "Association...".
Step 10: Ensure that your wizard looks as below and click "OK".
Working with LocalDb
Step 1: Open the Generate Database from Model by right-clicking on the design surface.
Step 2: In the next wizard click on New Connection and do as shown below:
Step 3: Click "OK" and if the wizard opens to create a new database, select "Yes".
Step 4: Select "Next" and the designer calculates to create the script of the database schema. Ensure that the Entity Connection Settings in the Web.Config option is checked.
Step 5: Click on "Finish" and the script opens. Right-click and select "Execute".
Step 6: Build your project. The Entity Designer creates two classes named College and Student and a model is added to your Models folder.
Step 7: You can now use the new ASP.NET Scaffolding as usual for the EDMX generated models. Now you can use your newcontext as a Data Context class while scaffolding as shown below:
Summary
This article will help you to create an Entity Model using the ADO.NET Model Designer and you can also use the new EDMX models in a ASP.NET Scaffolding. Thanks for reading.
In that context, we'll today work on this session to create an Entity Model and use it in the application.
So, let's proceed with the following sections:
- Application Creation
- Working with Entity Model
- Working with LocalDb
Create an ASP.NET Web Application in the MVC Project Template in Visual Studio 2013.
Working with Entity Model
Step 1: Just right-click on the Models folder to add an ADO.NET Entity Data Model named College.
Step 2: In the next wizard, select "Entity Model".
Step 3: The designer opens a blank model in which we add the entities. Just right-click on the designer to open "Properties".
Step 4: Set the Entity Container Name to CollegeDbContext as shown below:
Step 5: Right-click on "Design" then select "Add New" -> "Entity...".
Step 6: In the next wizard enter the entity name as College and CollegeId as the key column name and click "OK".
Step 7: Right-click on Entity to add a Scalar Property to it.
Step 8: Create the Name property also. Now add an another entity name Student and do the same as done above.
Step 9: Now right-click on design then select "Add New" -> "Association...".
Step 10: Ensure that your wizard looks as below and click "OK".
Working with LocalDb
Step 1: Open the Generate Database from Model by right-clicking on the design surface.
Step 2: In the next wizard click on New Connection and do as shown below:
Step 3: Click "OK" and if the wizard opens to create a new database, select "Yes".
Step 4: Select "Next" and the designer calculates to create the script of the database schema. Ensure that the Entity Connection Settings in the Web.Config option is checked.
Step 5: Click on "Finish" and the script opens. Right-click and select "Execute".
Step 6: Build your project. The Entity Designer creates two classes named College and Student and a model is added to your Models folder.
Step 7: You can now use the new ASP.NET Scaffolding as usual for the EDMX generated models. Now you can use your newcontext as a Data Context class while scaffolding as shown below:
Summary
This article will help you to create an Entity Model using the ADO.NET Model Designer and you can also use the new EDMX models in a ASP.NET Scaffolding. Thanks for reading.
No comments:
Post a Comment