Monday 13 December 2010

This weeks tutorial dealt with working with the Dynamic Data aspect of Visual Studio, giving a brief intoduction towards how it works and its abilities. Within this weeks tutorial we were asked to create a database which already existed, and link it using Dynamic Data. The process of completing this task was as follows:
  • Create a new website, using the standard process, ensuring that C# is selected from the left hand side of the window.
  • Global.ascx will be referred to later, but it provides the other pages in the website, hence its "global" name.
  • Continuing with the process of completing the Dynamic Data task, navigate to the AppData folder and choose to "Add an Exisiting Item" (this can only be done once the Northwind database has been downloaded from the online source). Nothing should happen once the database has been added into the web site.
  • Go back to the directory and add a new item, ensuring that Visual C# is once again selected (this is important otherwise the Global.ascx page won't be able to render the information correctly), then choose "Linq to SQL Classes" - A standard message should then appear on the screen, of which "Yes" should be chosen.
  • Dataclasses.dbml will then be created with items inside.
  • Once the Dataclasses.dbml object has been created, click on View, then choose "Server Explorer". This will then display a window down the left hand side of the screen, showing the Database which is now available, and also the machine number currently been worked on (university only). Double click on Northwind.dbml, then open the tables.
  • Add in the required tables (this will vary for each database, but for the Northwind database add the tables requested within the tutorial). Clicking and dragging the tables across into the main view will then show the relationships between the tables added. This will create a simple ER diagram.
  • The database should now be linked in.
  • Refer back to Global.ascx and uncomment the line that starts with "//DefaultModel" at the end of the first paragraph. Uncommenting the line is done by removing the 2 forward slashes at the start of the line.
  • Go to the "typeof" section within the line and change the code within the brackets to "DataClassesDataContext".
  • Go to the end of the line and set the "ScaffoldAllTables" option to true, instead of the default "false".
  • Go to the Default.ascx file down the right hand of the screen and choose to view the page in browser - this will then display the completed file in a web page view.
  • Checking if the system works can be done by clicking on the options available, and seeing if the tables open.
  • The tables do exist, however they won't appear within the DynamicData folder down the right hand side of the screen. The tables are stored in the AppCode section of the web site, within the Database.dbml file that was created earlier.

No comments:

Post a Comment