What is EntityFramework

What is Entity Framework

Entity Framework is an ORM framework. ORM stands for Object Relational Mapping

What is Object Relational Mapping framework

Object Relational Mapping framework automatically creates classes based on database tables, and the vice versa is also true, that is, it can also automatically generate necessary SQL to create database tables based on classes.
Step 1: create two tables in database

create table  Branhes(Id int primary key,Name varchar(50))


create table Students(Id int primary key,StudentName varchar(50),BranchId int  foreign key references Branhes(Id))


insert into Branhes values(1,'CSE');
insert into Branhes values(2,'ECE');
insert into Branhes values(3,'IT');
insert into Branhes values(4,'EEE');



select * from Branhes

insert into Students values(1,'SRINATH',1);
insert into Students values(2,'Ramu',2);
insert into Students values(3,'SumaLatha',1);
insert into Students values(4,'Gowri',1);
insert into Students values(5,'Sunitha',2);
insert into Students values(6,'Hari',4);
insert into Students values(7,'Pavan',3);
insert into Students values(8,'Santosh',3);
insert into Students values(9,'Prannetha',2);
insert into Students values(10,'Harsha',1);


select * from Students
Step 2: Open visual studio File->New-> project-> Add asp.net Empty Website ->name as Introduction To Entity frame Work->click on ok
step 3: right click on Project ->Add new item ->Select ado.net Entity data model ->name as Student Model->click on ok
Step 4: Then Entity Dtat Model Wizard open->select generate from database->click on next->click on new connwction button-> fill the infromation ->give connection string name in web.config As StudentDBContext ->click on next button
Step 4: choose your Database objects->select those tables branches and students ->give Model name As StudentModel ->Click on Finish
EDMX file generated

No comments:

Post a Comment