Working with ADO.NET Entity framework
After looking into the architecture of the Entity Framework, this article I will show the how to create an EDM using the Entity Data Model Wizard.
The Entity Framework compiles a set of conceptual and storage schemas, together with the mappings between them, into bidirectional pairs of Entity SQL statements called client views. These views drive query and update processing in the runtime engine.
Generating an Entity Data model
To generate an EDM you need to first add an ADO.NET Entity Data Model item template to the project. Follow the below given steps to add and EDM to the project
- Right-click the project, point to Add, and then click New Item.
- Select ADO.NET Entity Data Model in the Templates pane.
- Click Add after you enter the name for EDM. This will present the Entity Data Model Wizard.
- Select Generate from database in the Choose Model Contents dialog box. Then click Next.
- Click the New Connection button. The Connection Properties dialog box is displayed.
- Enter your server name, select the authentication method.
- Select the database name, and then click OK.
- The Choose Your Data Connections dialog box is updated with your database connection settings.
- Select all the tables from the dialog box and click Finish.
The Entity Framework tools generate a class derived from ObjectContext that represents the entity container defined in the conceptual model. The ObjectContext class supports queries against an EDM that return entities as objects, as well as creating, updating, and deleting entity objects. The Entity Framework supports object queries against an EDM. Queries can be composed using Entity SQL, LINQ to entities and object query builder methods.
Once the entity data model is generated you can use any of the above given methods to query your ObjectContext class.
For example :
using (BlogEntities entities = new BlogEntities())
var query = from blogentry in entities.blogentries
orderby blogentry.datepublished descending