Follow by Email

Saturday, July 6, 2013

Using Entity framework in example | Bind grid using Entity Framework | LINQ to entity data model

Hi in this post i will show how to use ADO.NET entity data model in

1. Go to your web application and Add New Item from the solution explorer called ADO.Net Entity Data Model. Giving the file name as myFirstModel.edmx

2.Then it will enter into Entity Data Model Wizard from there select "Generate from database" option. click on next and enter the database connection login details.

3. Then you will see a entity connection string getting generated. Save the entity connection string name as Test_DBEntities and click on next.

4. From the next screen choose the data objects you want to use and finish to exit the data model wizard.

5. After u click on finish, u may get a security warning just click on ok.

6. Now using entity framework we will bind a gridview

7. Below is the code :

protected void BindGrid()
            Test_DBEntities db = new Test_DBEntities();

            var GridData= from a in db.carWorlds select a;

            GridView1.DataSource = GridData.ToList();