This article describes the sequence of operations required to get up and running with an LINQ.
There are two methods for building the LINQ data model. This first method is to build a model by
hand using drag and drop to add objects to the model. We describe here firstly how to use the
second method which involves running a program called SQLMetal which ships with Visual Studio
to automatically generate the model. Then we also show an example of how to create a model from
scratch without using SQLMetal.
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).
Top of Page
SQLMetal and sqlmetalbuilder
As SQLMetal is a command line program supplied as part of the Visual Studio or VWD installation.
Below is an example of running the program (note we have copied the file SQLMetal to a more
convenient directory in this example).
This program is normally located on C:\Program Files\Microsoft SDKs\v6.0A\bin
Details for the command line usage can be found at
http://msdn.microsoft.com/en-us/library/bb386987.aspx
We would recommend that rather than use the command line program, download a friendlier interface
to work with from
http://sourceforge.net/projects/sqlmetalbuilder/
; this FREE utility is excellent to work with.
Once you have generated your dbml file, the file should be imported into your web site.
Notice that the Default.aspx is highlighted as selected in the soloution explorer window.
Make sure you click on the root as shown below.
Next right click and select to an App_Code folder..
Then click on the App-Code folder and right-click to add an existing item.
Note when browsing for the file you will need to change the
filter to show all file extensions, as shown below.
After you have imported the dbml file you need to link it to the database connection as
shown below (select New from the drop down if you do not already have any connections
setup in the website): -
Also check that the DataContext Name is appropriately named.
Copy and paste the Context Name into the appropriate menu in MUST+Web; this will enable our code
generators to correctly generate LINQ references when building the site.
Use the Web Conversion – Options and Settings.
Type or paste in the object name.
Top of Page
Updating the LINQ model for changes in your database
There is no built in feature for updating a model for changes made to your database design.
If you want to delete a field or a table, then highlight the object in the designer,
then press the delete key. For example shown below we could delete the field called freight
that is no longer in the database design.
Objects with more complex changes can be deleted, then using drag and drop from the
database explorer window added back into the model.
Similarly new objects can be dragged onto the model.
Top of Page
Updateable Views and LINQ<
When views are added to the model, they cannot be updated until you specify
a combination of one or more key fields.
Existing objects such as a view can be located using the property dropdown for navigation.
In order to make the following view updateable, select the field to act as the unique key.
Then set the field property to indicate that it is the primary key.
The view will now be updateable (subject to any other general restrictions on view updateability).
Creating a LINQ model from Scratch
Highlight the root or App_Code folder in the solution explorer.
Then select to add a new item.
Then enter the details for the LINQ data model.
Answer yes when prompted to generate the App_Code folder.
Then proceed to use drag and drop to add tables and views from the Database explorer onto the model.
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