How: Adding Entity Framework Reference using NuGet

Adding Entity Framework

If you have already added Entity Framework you might want to check this thread ASP.NET MVC using EF for actual using of Entity framework in your code. If this is your first time you can continue reading steps below on Adding Entity Framework.

Let’s Start: – Adding Entity Framework Reference

1. Open NuGet Package Manager to add EntityFramework. Go to Tools->NuGet Package Manager ->Manage NuGet Packages for Solution. 

Adding Entity Framework

2. Search for EntityFramework and click install button.

Adding Entity Framework

Search For EntityFramework

3. Wait for NuGet Package Manager to install EntityFramework.

Adding Entity Framework

4. The image below is the view of Entity Framework after it is already installed.

Adding Entity Framework

5. To check if EntityFramework is successfully added to your project go to your solution explorer and under your reference EntityFramework should be found.

Adding Entity Framework

Project Reference

Entity Framework

You have successfully added Entity Framework to your project. You can now use it in your ASP.NET MVC Web Application.

 


You might want to check this thread..

 

[pt_view id=”d88f6acsu0″]

How to Create Database using Visual Studio 2013(SQL Server)

How to Create Database

– Creating a Database is very common things in most of the developers, however for a beginner like me creating one is a bit of a struggle, especially if you are just starting to learn and understand programming. So I decided to create a simple instruction to share what I learn in different ways on how to access SQL Servers. If you are using Visual Studio as your development environment, it might be familiar to you if we are going to use Visual Studio SQL object Explorer to browse for the database. If not, let me guide you using simple instruction written below.

Let’s Start: 

1. First Open Visual Studio and go to View->SQL Server Object Explorer

How to Create Database

SQL Object Explorer

2. By default SQL Object Explorer contains available SQL server. You can also add Server by simply clicking on the icon with a plus sign located at the topmost part of your SQL Server Object Explorer

How to Create Database

Connect to database

3. After clicking on the add server icon, a dialog box will show. Input server name to add the server to your Object explorer. You can use Windows authentication for authentication type, however if you set a password for your server, you might need to input valid credentials for your authentication.

How to Create Database

Connect to Server

4. Image below is my local server I added in my SQL Server Object Explorer.

How to Create Database

SQL Server Object Explorer

5. Add database to your server, expand your server and right click on Database folder then Select Add New Database. See image below.

How to Create Database
How to Create Database

Add Database

6. Create Database window will pop-up. Name your database to your likings.

How to Create Database

Name Database

7. Creating a Table. Navigate again to your SQL server, expand Database folder and under your Database right click on the Table 

How to Create Database

Add Table

8. A new window should be open in the middle pane containing default id column which is set to primary.

 

How to Create Database

Table design

9.  Set id to auto increment by highlighting the id column and going to properties located just below your solution explorer. Expand Identity Specification and set (Is Identity) to true.How to Create Database

10. Now go back to the middle pane and add additional column we need for our table.How to Create Database

11. To save changes you made to your table click on update button located above your table design then click Update Database on the next pop-up window which is the image below.How to Create Database

12. To see if table is successfully created go to your SQL Server Object Explorer and expand your database and go under Table If you haven’t see your table yet right click on your database an click refresh.                         How to Create Database

13. You can also view table data by right-clicking on your table and selecting View DataHow to Create Database

14. And in the middle pane, you can see available data for your table.How to Create Database

You’re done!

Thank you for reading!!

Happy Coding!!

 


Post you may like:

[pt_view id=”2384ae03it”]

Viewing of SQL Database Connection String in Visual Studio

SQL Database Connection  – To view Database Connection String using Visual Studio. Open your Visual Studio IDE and navigate to View-> SQL Server Object Explorer.

SQL Database Connection

SQL SERVER OBJECT EXPLORER

Then navigate to SQL Server Explorer from the left pane of your development Environment.

SQL Database Connection

Server Object Explorer Location

Connect to your server using the button with plus sign located at the top of the Server Object Explorer.

SQL Database Connection

Connect to Server

From the dialog box select the server you want to connect. Then click connect.

SQL Database Connection

Choose Server

Navigate to your Database of which you want to view its connection string.

SQL Database Connection

Select Database

Click on your Database and go to properties located just below your solution explorer then go to connection string.

SQL Database Connection

    Properties

Copy connection string and paste it  to your application for your database connectivity

Thank you for reading. Happy coding!!

Basic ASP.NET MVC Web Application Implementation

What is MVC?

  • Model View Controller (MVC) is a framework, a Programming architecture where you designed your code in 3 different modules. Model, it is where all your logical properties or data are declared. View, it is where you designed or creates your Client user interface and lastly Controller, it is where you process data and connect model to view.

MVC Diagram:

To illustrate how MVC work in ASP.NET lets create a sample project.

To be guided with the sample Project. Below are the names I used for the function.

Note:  I’m using visual studio 2013 for this tutorial

  • MVCBasicModel.cs => Name of the Model Class(Located under Models Folder)
  • HomeController.cs => Default controller generated by Visual studio after Creation of new     MVC Application Project(Located under Controller folder)
  • Index.cshtml => Default view for HomeController(Located under Views/Home Folder)

Goal: 

  • Generate data from database
  • Save in a list with model binding
  • Pass to view and display in a table

Output Preview:

To begin let’s create a new Project in Visual studio. You can also refer to my blog how to start with ASP.NET MVC Web application for detailed instructions on how to start a project.

  1. First open your Visual Studio. Navigate to File/New and then Choose Project right on top of your Visual Studio IDE.
  • IDE => Integrated Development environment
  1. New Project options will popup. Select Visual C# from the left side panel and Search for ASP.NET Web Application from the right side panel, then Click OK.
  2. After that select a template, which is MVC then click ok to proceed
  3. Congratulation!! You have successfully created your MVC project.

Now let’s create a Database and table. There are two ways in creating a database; you can use a SQL management studio or via Visual Studio. Here I’m going to use Visual Studio.

Note:  You need to have SQL Server installed on your machine to proceed with these steps

  1. To open SQL Server Explorer in Visual Studio Navigate to View from the menu bar and then click on SQL Server Object Explorer. SQL Server Object Explorer will show on left side of your visual studio IDE.
  2. Navigate to your local SQL Server. Right click on the Database folder and then click Add New Database. You can name it whatever you like, for me I name it as sad_db.
  3. After that navigate to your local SQL server again and under that you can see you’re newly created Database. Open your newly created database and go to Table Right Click on it to see add new Table option.
  4. Then add columns to your table.
  • Id => int
  • Employee_Name => varchar(100)
  • EmpCode => varchar(100)
  • Position => varchar(100)
  • Location => varchar(100)
  1. To manually insert sample data. Right click on your table again and choose view data.
  • Id => 1
  • Employee_Name => John
  • EmpCode => j-123
  • Position => Cashier
  • Location => Place

And now let’s proceed with the coding part. Let’s add our model class. From your solution explorer located on the right side panel of your Visual Studio IDE, navigate to the Model folder, then right click on it and select add option, then select the class. Name it as MVCBasicModel. This model will be used to bind with a list in our controller.

Declare these properties from your MVCBasicModel class:

In our HomeController.cs (Located under Controller folder from the solution explorer) create a separate function/method that will fetch data from our database and return data as a list. Name it as GetData ();

Note: To view Database Connection String navigate to SQL Server Object Explorer, right click on your database and then click properties. Under properties go down to Connection string then copy and replace SQL Connection string from the code below.

Passing data to the View

In your HomeController Index call our function GetData() to get the data we fetch from our database and return it  into our view, which is index.cshtml located under view/Home Folder

Index.cshtml

  • @model IEnumerable<MVCBasic.Models.MVCBasicModel> => to gain access the list we pass from our HomeController
  • Use foreach loop to manually fill our data to our table

and we’re done.. Thank you for reading. Happy coding!!

 

Code Summary:

MVCBasicModel.cs

 HomeController.cs

Index.cshtml


Related Post:

 

[pt_view id=”2384ae03it”]

ALTERNATIVE SYSTEM(Visual Basic)

This system is created with a specific database. The system involves modification and auto-generation of data needed for reporting. Corrections of wrong Data Entry.

Language: Visual Basic

Database: Visual FoxPro(dbf)

Function:

  •    Login Authentications
  •    Generate data for Sales report
  •    Modify Wrong Entry Data
  •    Update Data for correction
  •   Delete unnecessary data after corrections