Saturday 6 January 2018

Entity Framework In Asp.net with MVC


Step 1:

Select File > New > Project. In the New Project dialog select Templates





Select Asp.net mvc4 application->E_Framework(Name)->OK




   Select Basic from template->OK







Project:E_Framework





Step 2:

Open server explorer-> Right click on data connections->Create new sql server database




Choose your server name-> (Ex:COMP1\SQLEXPRESS)
Provide your database name ->(Ex: LP92) ->OK





Right click on the table->Add new table




Put your field name and datatype(Ex:Id,Name,Password)




Set Id as primary key
Save the table (ctrl s) ->Put table name (Employee)->ok






Step 3:

Create model
Right click on the model->add-> class




Class (Emodel.cs)->Add





Write the code (Emodel.cs)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace E_Framework.Models
{
    public class Emodel
    {
        public int Id
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }


        public string Password
        {
            get;
            set;
        }

    }
}       



Step 4:

To add an entity, right-click on the project (E_Framework)





Add > New Item > Data > ADO.NET Entity Data Model.






Choose (Generate from database)->Next





Choose Database->Next




Select on checkbox(table->dbo->Employee)->Finish




Click on OK ->OK






Step 5:

Build the application

Right click on the project E_Framework->Build it





Step 5:

Add controller

Right click on controller-> Add->Controller





Name:(HomeController)
Template: Choose MVC controller with read/write actions and views, using Entity framework
Model class: Employee(E_Framework)                   //Table name
Data Context class: LP92 Entities(E_Framework)    //Database name




Step 6:

Run the application




Click on Create New(Add information)




Output:



No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...