Introduction
This post explains how to create a Model from the database using ASP.NET Entity Framework. Using Entity Framework you can define the flexible mapping to existing relational schema.
Here I have created a new console application to explain the ASP.NET Entity Framework. You need to install the VS 2008 SP1 to work with the ASP.NET Entity Framework.
1. Right click the Project and Create a Data Model for database by selecting
Add New item option. It looks like the following screenshot.
2. It prompts you to select the option for Model from dialogue box
3. Specify the Database Connection and it generates the Entity Framework
connection string which will save in the web.config file.
The metadata section in the connection string specifies how to interact the objects with the database. csdl describes the model. ssdl describes the database model and msl describes the mapping between model and database model. Next part in the connection string is database provider here we are using SQL provider and last part is connection string for the provider.
4. Choose the database objects to build the model.
From the above dialogue box we can choose desired tables, views and stored procedures.
5. Now Entity Frame work generates the default model and entities in the
Project.
Navigation properties in the above model describes mapping between the models.
6. Establish the object context to interact with entities.
7. We can see the results by executing the project
Conclusion
What we have done is we have taken a existing database to generate the Entity Framework model then we used object context to show the data from the database.
ASP.NET 3.5 Entity Framework …
You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…
simple and ez… but can u provide something related to implement this in webservices or smthing like that..
thaks and regards
HIRA GULROO
PAKISTAN
Why have you included the namespace BloggingModel in the above example? I ran the application by commenting that line!!