Wednesday 18 December 2013

Entity Framework In Some Simple Steps

Entity Framework: Entity Framework is the Hot-Cake of Today. This enables programmer a Bug free database operation using simple some commands. It is a Strong framework and easy to implement.

Definition : Entity framework is an Object Relational Mapper (ORM).It is basically generates business objects and entities according to database tables and provides the process for CRUD  (Create Operation, Read Operation , Update Operation  And Also  Delete Operation. )


Above diagram explain the structure of Entity Framework in the respect of .net Technology.
Then it is clear that Entity Framework resides on or above the ADO.net. That means we are using the Entity Framework as usual but the difference is that we are not handling the connection the command directly.
Process of adding an EDMX file: [Note: To use entity framework you must install the .net Entity Framework.]
Click the Finish button to Finish the operation.
Here I have Entered “Contact.edmx “ .
I have the following Field in My Table Contact.
To Add
A single Contact:
TestEntities DB = new TestEntities();
Contact Con = new Contact();[This is the object of Contact Model]
Con.lname = txtLname.Text.ToString();
Con.fname = txtFname.Text.ToString();
Con.phone = txtPhone.Text.ToString();
Con.Roll = txtRoll.Text.ToString();
TestEntities OB = new TestEntities();[TestEntities Object Will Handle The DataBase Operation And Will Generated Automatrically in The EDMX file]
OB.Contacts.AddObject(Con);[Adding a New Object For New Contact]
OB.SaveChanges();[This will affect the Real DataBase ]

Try your Self to Delete, and Update Data
If you made any changes in the database  then just :-
Click the Update Model from DataBase
Changes will be made automatically.








No comments:

Post a Comment