My presentation on ASP.NET Dynamic Data which is a new feature in the .NET Framework 3.5 SP 1 and allows for data driven websites to easily be constructed.
PrepOpen Visual StudioOpen SQL Server Management StudioMake sure have v1 of the databaseHave ZoomIT running
In VS 2008 -> new website -> 3.5 Framework (point this out) -> Dynamic Data Web ApplicationServer Explorer -> Add new connection -> SQL database (make sure you select the sql client) -> Expand/Show databaseSolution Explorer -> Add new item -> LINQ to SQL classes -> Call it spacedataDrag the tables from the server explorer onto the LINQ to SQL design surface -> SaveOpen the SpaceData.design.cs file -> Show the fact it’s a partial class (good spot quiz time) -> and the attributesOpenglobal.asax -> Uncomment the line beginning with model.RegisterContext,Set the context to SpaceDataDataContextand set scaffold all tables to true.RUN!Things to show:It’s not very prettyUnder astronauts the ID is showing, explain that we haven’t told it anything about itShow an editShow an insert and it’s spectacular fail;Paging/Sorting/Results per pageURL naming structureStop the app, and in the global.asax comment out the first route and un-comment the second route. Run the demo again: AJAX!!!!Last stop the app, remove scaffolding all and run again – errors!*
Stop the demo -> Add existingfile -> SpaceDataMetadata.csPoint out the classes are partial and have been annotated. Re-run the app and note that only the tables we want shown are.Next explain about the issue caused by not being able to overload propertiesCreate private class within the public class and add a property in it for ID and Name. Set to object type, explain why that works and how it is helpful.Attribute ID with ScaffoldColumn(false) (since the DB will handle this) and the Name with Required, string length and UI hint.Set the metadatatype of the public class to typeof(class) [ScaffoldTable(true)] [MetadataType(typeof(AgencyMetadata))] public partial class Agency { private class AgencyMetadata { [ScaffoldColumn(false)] public object ID { get; set; } [Required(ErrorMessage="The agency name is required")] [StringLength(10,ErrorMessage="This field is limited to 10 characters")] [UIHint("The name of the agency")] public object Name { get; set; } } }7. As a final step import the v2 version with all the hints. Point out the display name on spacefaring countries!*
Explain that it is still ASP.NET – This is additiveOverwrite the style sheet with the custom oneOpen the site.master page and change the page title (HTML and body) and add an image to it. Set image height/width to 75Now point out the dynamicdata folder in the solution. Point out the various sub folders and show what is in them. Explain that this isn’t rocket science it’s just dev ;)*
In solution Explorer -> Dynamic Data -> Field Templates -> Add new item Dynamic Data Field -> Spinner.ascxShow how it creates the edit version. Delete the non-edit version because we are happy how this displays normally. Remember to mention insert mode items can exist too!Copy code out of spinner front and back and explain what it doesAdd the attribute to the field [DataType("Spinner")]Demo the coolnees*
Point out the spacefaring name doesn’t show!Explain the data type is wrong also say what if the DBA makes some changes (say new tables for sex and species and updates the astronauts?). Restore v2 DBOpen the design surface for the data context. Show the fields have not autoupdated. This is good – it’s safeRemove astronaut and space faring and re-add them with sex and specifies. Point out the fact that if we had editted the auto generated code, we would have lost that work. This is why we use the partial class.Run the demo – Show the column for space faring now works!Show the new fields on astronauts! Show how the space suits don’t work. (Spot question why?)Add meta data from file. Show results*