Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Entity Framework in ASP.NET

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 198
    Comment on it

    Entity Framework (EF) is an ORM framework. ORM stands for object-relational Mapping.

    Now what is object-relational Mapping..

    Object-Relational Mapping framework it self creates model classes depending on tables of database, and vise versa. It can also creates required SQL to create database tables depending upon model classes.

    To deploy Entity Framework in asp.net we first have to install EntityFramework to our system and To install EntityFramework, we have to run the following command in the Package Manager Console and than type and run the command

    PM> Install-Package EntityFramework -Version 6.1.3
    

    This will add Entity framework to your Visual Studio.

    Now for an example Lets create some tables in our Database (Ex. Departments, Employee)

    CREATE TABLE Departments
    {
    ID INT PRIMARY KEY INDENTITY,
    Name NVARCHAR(50),
    Location NVARCHAR(50),
    }
    
    
    CREATE TABLE EMployees
    {
    ID INT PRIMARY KEY INDENTITY,
    FirstName NVARCHAR(50),
    LastName NVARCHAR(50),
    Gender NVARCHAR(50),
    Location NVARCHAR(50),
    Salary INT,
    DepartmentId int FOREIGN KEY REFERENCES Departments(Id)
    }
    

    Now in our project where we want to deploy EntityFramework we have add ADO.NET Entity Data Model with name EmployeeModel.edmx by selecting the option Generate from database, here we have to define the connection from our Database, so we Define a new connection here.

    Now we can select our table, Views and StoredProcedures wich are present in the Database, as for the Model Namespace we can define our own Name here (Ex. EmployeeModel).

    Now this is going to generate Entity Model for us automatically and it will add file with name EmployeeModel.edmx

    Now by using this file we can perform various operations on our database.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: