Introduction: This is a simple application that show how to create model class to Link to Sql in MVC ASP.NET. In this application we first create the database after that create the schema and insert the data. After that we add the one Linq to SQL class in the model folder and drag and drop a table schema. We know that MVC is the separated word that is models,views,controllers. In model folder we have create the business logic.views is provide GUI and last controller handle the all request provide by models and views.ASP.NET MVC provide some tools that used add the data base in your application easily. This is a very simple program I hope it's very helpful for beginners and solve the problem how to create database in a MVC application.

Step 1: Open Visual Studio 2010.

start.gif

Step 2: Next step add one folder in Solution Explorer.

addfolder.gif

Step 3: In a App_Data folder, add Sqldatabase.

database.gif

Step 4: After adding the SQL database, two files are created in the folder.

jiijui.gif

Step5: Open the Server Explorer.

server.gif

addtable.gif

savetable.gif

saveteb.gif

Step6: Set the primary key

setprim.gif

Step7: Open table

tabledata.gif

Step 8:Add Linq to SQL class.

add-database..gif


linktosql.gif
droptable-inlinqtosql.gif