In the previous post you have create the project to work on the AdventureWorks web API application . Next we are going to add the data access layer using the Entity Framework.
Entity Framework is a tool which maps the database objects to the model objects. It provides the medium to execute the CRUD command to the database without writing any SQL statement. for more information on Entity Framwork you can visit this link
Next we are going to add ado Entity model for our project Right click on the Model folder in the solution explorer , go to add and then click on the ADO.NET Entity Data Model.
It will ask to the Name
change Item Name to “AdventureWorksDB” and click on OK
It will display Entity Data Model wizard
Select “Generate from database” and click on Next.
Now it will ask you to choose data connection.
Next click on the new connection , it will ask you for the connection properties.
Enter server name , authentication type(Windows or SQL) and then select the database , after it click on the Test connection button to make sure what you have entered is connect.
if it succeeded then we are ready to go. click on the ok button on both window.You will come back to choose connection window.
For this time , we are selecting Yes from the options button, after it click on next , it will ask you to select database tables , views stored procedure, select all and then update the model name to “AdventureWorksModel”
After that click on finish button. it will open the model design file.
Now the interesting thing , you got the blank diagram file which is not expected.
This the because of the Production.Document table
Lets take a look this table.So the problem is the Entity framwork not understand the hierarchyId data type.
For now the easiest workaround is to exclude this table (we will fix it in forthcoming posts) and select others.Right click on the diagram file and select “Update Model from Database”
it will display the Update Wizard , select all but not Document table
we are done, just save the file and rebuild the solution again using the build menu.
Thanks for reading , hope you find this post useful . 🙂