MUST+Web, a complete translation end-end of Access to SQL Server and for Visual Studio. Click to see demonstration web site
MUST Logo

Getting started with the Entity Data Model

This article describes the sequence of operations required to get up and running with an Entity Data Model. It also describes how to avoid potential problems should you delete and then need to recreate the Entity Data Model. There are also some additional details on how this ties into our product.

The screen-shots shown here are taken from Visual Web Developer 2008 Express Edition, similar steps are required when working with Visual Studio.

Creating a new web site and EDM

First start by creating a new ASP.NET web site.



As shown below select your language VB or C# and then give the site location a name (shown as Example in our screen-shot).



Next notice that the Default.aspx is highlighted as selected in the soloution explorer window.



Make sure you click on the root as shown below (unless you already have a folder called App_Code in which case click to highlight that folder).



If you attempt the steps we are about to describe and receive the following error message, then it means that you have not clicked into the root (or App_Code folder if present) as described above.



Next use the Add New Item menu to add an “ADO.NET Entity data Model”.



As shown below:-



Answer YES when prompted to create the App_Code folder.

As shown below:-



Now select to generate your model from your existing SQL Server database.



Now create a new connection, or pick from an existing connections to link to your database.



Next you can select the tables and views to include in your model, when working with our products select all tables and views.



Once the model is constructed, then click on the background as shown below and then copy and paste the Entity Container Name into the appropriate menu in MUST+Web; this will enable our code generators to correctly generate EDM references when building the site.



Use the Web Conversion – Options and Settings.



Type or paste in the object name.



At this point our own product specific instructions should be consulted for building the site.

Top of Page
EDM and missing views

To update the EDM right click on the EDM and display the shortcut menu shown below.



Expanding the list of views, you may see some views that can not be added to the EDM.



In these views the EDM is unable to work out an underlying key (normally deduced from the tables under-pinning the view), so these views cannot be added to the model. An example of a view for which the keys cannot be established is shown below.



For these views you will need to use a SQLDataSource or possibly a LINQDataSource. Note that often these views if present are used for DropDownLists and our product will automatically use a SQLDataSource on DropDownLists to avoid this specific problem.

Top of Page
Updating the EDM for changes in your database

For new fields or tables added to the database, proceed as described above to update the EDM.

Below is an example where we have created a new view and then updated the model to reflect this.



Then we have added another field to the view and updated the model.



Next we see that when we remove an existing field from the database and update the model, the field does not automatically get removed from the EDM, but generates an error indicating a problem.



To resolve this, highlight the field as shown below and then press the delete key to remove the field.



After deleting the field pressing the save button will save the EDM and you will see the error notification is removed from any list of errors.

If a field name is changed, then updating will show both the new and old names, the old name should then be deleted.

If a field data type is changed, then be very careful that the changes are correctly referenced in the appropriate field details in the EDM. Manual adjustments maybe required.

Top of Page
Re-generating the EDM

If you need to start again with an new copy of the EDM then proceed as follows.

Delete the Model but leave the App_Code folder.



If you also look in the web.config file you will see an entry corresponding to your EDM (look for the keyword metadata in the string if you have difficulty identifying the connection, this will look unlike any other connection strings you may have). You need to delete this entry. Otherwise, you will have problems when you come to re-create the EDM with the same name as you are already using.



Leaving the tags and any other existing connections information unchanged .



Next highlight the App_Code folder in the solution explorer.



Then select to add a new item.



You can now proceed as described earlier in this document to repeat the process of generating the EDM.

Top of Page

MUST+WEB converting Access Databases to .net with Visual Studio or Visual Studio Express. Supports development in Visual Basic and C# using either SQL, LINQ or EntityData Model data sources. Click below to improve your development productivity.

Top of Page

by Andrew Couch Office Access MVP, Director ASC Associates andy@ascassociates.biz