Answer on Question#38765- Programming, C#
1. BS Bank Inc wants to add some additional features in the application. The company asks FIT technologies for the following additions: [15 Marks]
? BS Bank Inc. needs to add modules to provide the following services:
a. Online share and mutual funds trading
b. General insurance for health, car, and travel [10 Marks]
BS Bank Inc. should be able to provide other services like bill payments, mobile recharge. [5 Marks] [Use static variables and static function to implement this.]
Solution.
Create a new ASP.NET Web Application
Create a new project in Visual Studio, and select the ASP.NET Web Application template. Name the projectContosoSite.
Click OK.
In the New ASP.NET Project window, select the MVC template and click Create Project.
New ASP.NET Project - ContosoSite
The project is created with the default files and folders.
Generate the models
You will now create Entity Framework models from the database tables. These models are classes that you will use to work with the data. Each model mirrors a table in the database and contains properties that correspond to the columns in the table.
Right-click the Models folder, and select Add and New Item.
In the Add New Item window, select Data in the left pane and ADO.NET Entity Data Model from the options in the center pane. Name the new model file ContosoModel.edmx.
Click Add.
In the Entity Data Model Wizard, select Generate from database.
Entity Data Model Wizard
Choose Model Contents
What should the model contain?
Empty model
Creates an entity model from a database. Object-layer code is generated from the model. This option also lets you specify the database connection, settings for the model, and database objects to include in the model.
<previous> <next> <finish> <cancel>
Click Next.
Select the data connection you added earlier.</cancel></trex></previous>
Entity Data Model Wizard
X
Choose Your Data Connection
Which data connection should your application use to connect to the database?
tomfitz-note3\localdb#7663d4c9.ContosoUniversity.dbo
☑ New Connection...
This connection string appears to contain sensitive data (for example, a password) that is required to connect to the database. Storing sensitive data in the connection string can be a security risk. Do you want to include this sensitive data in the connection string?
☐ No, exclude sensitive data from the connection string. I will set it in my application code.
☐ Yes, include the sensitive data in the connection string.
Entity connection string:
metadata=res://*/Models.ContosoModel.csd|res://*/Models.ContosoModel.ssd|res://*/Models.ContosoModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\v11.0;initial catalog=ContosoUniversity2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
☑ Save entity connection settings in Web.Config as:
ContosoUniversityEntities
<previous> | <next> | Finish | Cancel
Click Next.
Select Tables to generate models for all three tables.</previous>
Click Finish.
If you receive a security warning, select OK to continue running the template.
The models are generated from the database tables, and a diagram is displayed that shows the properties and relationships between the tables.
The Models folder now includes many new files related to the models that were generated from the database.
The **ContosoModel.Context.cs** file contains a class that derives from the **DbContext** class, and provides a property for each model class that corresponds to a database table. The **Course.cs**, **Enrollment.cs**, and **Student.cs** files contain the model classes that represent the databases tables. You will use both the context class and the model classes when working with scaffolding.
Before proceeding with this tutorial, build the project. In the next section, you will generate code based on the data models, but that section will not work if the project has not been built.
Comments