This is just a step by step walkthrough for the database approach with the Entity Framework 4.0, which means that i am using the “old” ObjectContext instead of the “new” EF 4.1 DbContext.
Create a new Console Project
Add a new Item to your project. Take the “ADO.NET Entity Data Model” template. Choose your prefered name. In my case i take myheco because i want to create an model for a database called myheco.
Choose “Generate from database” in the upcoming window
Next, choose your connection. In my example, i decide to save the connection settings in the app.config with the name “myhecoEntities”. This will be name for your context in your code if you don’t create your own implementation of the ObjectContext!
Choose your tables, views and stored Procedures you want to use and set your prefered options
Take a look at the Solution. It should look like this
Let’s try to use our OR-Mapper with LINQ-To-Entities
If you make changes to your Database Schema, you’ll need to update your model. You can do this by opening the Entity Data Model file (edmx) with a double click. Right click on an empty space and choose “Update Model from Database”
Choose the “Refresh”-Tab on the upcoming dialog and press “Finish”.
Now it depends on your database changes you’ve made if your solution still compiles.
Mit Tag(s) versehen: EntityFramework