In this article i will explains you how to use Entity Framework CodeFirst Approach for Existing database with POCO class generated on the fly (Auto Generated)
Since we want to generate POCO class on the fly we have to download EF4.x POCO Entity Generator for C#
Step 1: Download EF4.x POCO Entity Generator for C#
http://visualstudiogallery.msdn.microsoft.com/23df0450-5677-4926-96cc-173d02752313
Step 2: Create Visual Studio Project
Step 3: Choose Internet Application Template
In order to generate POCO class for existing database for EF Code First
Step 4: Right Click Project in Solution Explorer, then Click on Entity Framework and then click on Reverse Engineer Code First
Step 5: Make Connection to your existing database and Test Connection
And this will generate all necessary POCO class for your database.
Here is how your Model folder looks after POCO class auto generation completes.
Step 6: Build your Asp.net MVC Project to make sure that everything is working
Lets Displaying Customer Records
Step 7: Right click controller folder and choose Add Controller
Step 8: Name it as CustomerController and Choose Customer for Model and NorthwindContext for DBContext
Click ok and it will generate CRUD Operations for Customer Class
Step 9: Run the Project and Type following in URL
I hope you enjoyed this article. With All new support for Entity Framework now you can very easily use CodeFirst approach for your existing database.