ASP.Net 3.5 SP1-
  Dynamic Data



Michał Morciniec – GPSD Spain
micham@microsoft.com
Agenda

• Dynamic Data
   – Concepts and Architecture
• Project creation in VS 2008 SP1
• Dynamic Data Website Elements
  ...
Architecture


                                    Page and Field Templates

                                    Entities,...
Dynamic Data Concepts

• Makes easy to create data driven web sites
  (operaciones CRUD)
• UI is inferred from the Data Mo...
Dynamic Data WebSite – Creation 1

• Use template
  “Dynamic Data Web
  Site”



• Web Site Project
  contains “Dynamic
  ...
Dynamic Data WebSite – Creation 2

• Add LINQ to SQL o
  LINQ to Entity
  classes to project



• Note - App_Code
  folder...
Dynamic Data WebSite – Creation 3

• Create data
  connection, drag
  tables to designer of
  Data Model

• Data Model (cl...
Dynamic Data WebSite – Creation 4

• Configure Data Model class (a.k.a.
  DataContext) in Global.asax in
  RegisterRoutes(...
Dynamic Data-Creation DEMO
Page Templates

• Located in Dynamic
  DataPage Templates
• Page Uses Controls-
  –   DynamicDataManager
  –   DynamicVali...
Page Modes

• Separate-Page Mode (default)
   – Separate pages used to list, edit and insert new data
• Combined-Page Mode...
Separate-Page Mode

• Uses following route in Global.asax
   – {table}/{action}.
• {action} can be
   –   Edit      routes...
Combined Page Mode

• Uses following routes in Global.asax
   – {table}/ListDetails.aspx
• Same page ListDetails.aspx used...
Page Modes combination

• Each entity can use its Page Mode:
• Order is significant
             routes.Add(
             ...
Field Templates

• Dynamic Data selects controls
  based on field datatype
   – Boolean shown as checkbox
   – Relationshi...
Field Templates

• Fields with unknown datatype are not displayed
• Atribute UIHint associates control with datatype
   – ...
Custom Page Templates

• Page Templates can be designed
• They follow naming convention
  – DynamicDataCustomPages{entity_...
Custom Page Templates

• Tipically, page markup contains DynamicField control
   – Concrete control for field is selected ...
Custom Field Template

• It is possible to modify control associated with a datatype
   – Associate Calendar control with ...
Custom Field Template-Edit Mode

• Use ExtractValues() to write control data to
  DB


      protected override void Extra...
MetaData application

• Dynamic Data uses MetaData specified in the Data Model
   – But when model is regenerated changes ...
Data Validation

• Can use metadata
                                    public class CustomerMetadata {
   – [Required()] ...
Data Validation

• Using Validate event (Global)
   – OnValidate fires on change for any field
   – You can filter on type...
Customization-DEMO
Dynamic Data Wizard

• Facilitates creation of Dynamic Data web sites
• In development
   –   Not part of the .Net 3.5 SP1...
Dynamic Data Wizard
Step1: Data Model

• Data Model
  – New Data Model generation
  – Can select existing model
Step2: Choose Entities for the Model
•   Table selection
•   Can specify Namespace
•   Can specify class name ( “DataConte...
Step3: Page Template Selection

• Wizard generates Custom Page Templates
  – Template for a list view (List)
  – for detai...
Step4: Operation Customization

• Select/Restrict operations type
   – edition, insertion, deletion, details
• You can sel...
Dynamic Data Wizard - Summary

• Data Model is generated (DataContext) and the Page
  Templates
• All Page Tempates go int...
Dynamic Data Wizard - DEMO
Summary

• Dynamic Data facilitates creation of data-driven web
  sites
   – Increases development productivity
   – Simpl...
References
•   Introduction to ASP.NET Dynamic Data-Dynamic Data in Action Webcasts
     – http://www.asp.net/dynamicdata/...
Upcoming SlideShare
Loading in...5
×

ASP.Net 3.5 SP1 Dynamic Data

7,235

Published on

In this presentation we will have a look at the Dynamic Data functionality introduced in ASP 3.5 SP1. We will examine the architecture, concepts and main components of this framework such as Page Modes, Page Templates, Field Templates and Validation. We will discuss customization options for this type of projects. We will also have a look at the Dynamic Data Wizard tool that did not make into the RTM but may assist you in creation of Dynamic Data web sites.

Published in: Technology, Business
2 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total Views
7,235
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
466
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

ASP.Net 3.5 SP1 Dynamic Data

  1. 1. ASP.Net 3.5 SP1- Dynamic Data Michał Morciniec – GPSD Spain micham@microsoft.com
  2. 2. Agenda • Dynamic Data – Concepts and Architecture • Project creation in VS 2008 SP1 • Dynamic Data Website Elements – Page Templates, Page Modes – Field Tempates • Customization – Custom Page Templates, Custom Field Templates – MetaData application, data validation • Dynamic Data Wizard
  3. 3. Architecture Page and Field Templates Entities, Field, Partial classes, Classes, Metadata Attributes Tables, columns, constraints LINQ to SQL Page generated dynamically Data Source Data Model Data Model Meta-data application
  4. 4. Dynamic Data Concepts • Makes easy to create data driven web sites (operaciones CRUD) • UI is inferred from the Data Model • Data Model uses metadata to describe the structure and data relationships. • Basic data validation rules are imposed automatically • Pages are generated automatically based on templates • URL Routing feature is used to map URLs to pages.
  5. 5. Dynamic Data WebSite – Creation 1 • Use template “Dynamic Data Web Site” • Web Site Project contains “Dynamic Data” folder
  6. 6. Dynamic Data WebSite – Creation 2 • Add LINQ to SQL o LINQ to Entity classes to project • Note - App_Code folder is added with the Data Model (.dbml)
  7. 7. Dynamic Data WebSite – Creation 3 • Create data connection, drag tables to designer of Data Model • Data Model (classes ) is generated in “code- behind” associatesd with the model (.designer.cs)
  8. 8. Dynamic Data WebSite – Creation 4 • Configure Data Model class (a.k.a. DataContext) in Global.asax in RegisterRoutes() MetaModel model=new MetaModel(); model.RegisterContext( typeof(NorthwindDataContext), new ContextConfiguration() { ScaffoldAllTables = true } );
  9. 9. Dynamic Data-Creation DEMO
  10. 10. Page Templates • Located in Dynamic DataPage Templates • Page Uses Controls- – DynamicDataManager – DynamicValidator – FilterRepeater – DynamicControl – DynamicField • GridView used to show data.
  11. 11. Page Modes • Separate-Page Mode (default) – Separate pages used to list, edit and insert new data • Combined-Page Mode – Data is manipulated in the same page • Different Page Modes can be associated with different tables (entities)
  12. 12. Separate-Page Mode • Uses following route in Global.asax – {table}/{action}. • {action} can be – Edit routes.Add( – List new DynamicDataRoute(quot;{table}/{action}.aspxquot;) { – Details Constraints = new RouteValueDictionary( new { action = quot;List|Details|Edit|Insertquot; }), – Insert Model = model }); • Every operation uses different page – No “in-line” editing
  13. 13. Combined Page Mode • Uses following routes in Global.asax – {table}/ListDetails.aspx • Same page ListDetails.aspx used to manipulate data and show detail – “in-line” editing routes.Add( new DynamicDataRoute(quot;{table}/ListDetails.aspxquot;) { Action = PageAction.List, ViewName = quot;ListDetailsquot;, Model = model }); routes.Add( new DynamicDataRoute(quot;{table}/ListDetails.aspxquot;) { Action = PageAction.Details, ViewName = quot;ListDetailsquot;, Model = model });
  14. 14. Page Modes combination • Each entity can use its Page Mode: • Order is significant routes.Add( new DynamicDataRoute(“Products/{action}.aspxquot;) { Constraints = new RouteValueDictionary( new { action = quot;List|Details|Edit|Insertquot; }), Model = model, Table = “Products” }); routes.Add( new DynamicDataRoute(quot;{table}/ListDetails.aspxquot;) { Action = PageAction.List, ViewName = quot;ListDetailsquot;, Model = model }); routes.Add( new DynamicDataRoute(quot;{table}/ListDetails.aspxquot;) { Action = PageAction.Details, ViewName = quot;ListDetailsquot;, Model = model });
  15. 15. Field Templates • Dynamic Data selects controls based on field datatype – Boolean shown as checkbox – Relationships shown as drop down list – Text show as TextBox or Literal • Pages use Field Templates to show control at runtime – Controls do not form part of Page Template markup, injected at runtime • FieldTemplates are stored in DynamicDataFieldTemplates – “Intrinsic types”
  16. 16. Field Templates • Fields with unknown datatype are not displayed • Atribute UIHint associates control with datatype – Substitute control for known datatype – Assign control for “unknown” datatype • Field data is displayed using markup – <%# FieldValueString %> – <%# FieldValueEditString %> (edit mode)
  17. 17. Custom Page Templates • Page Templates can be designed • They follow naming convention – DynamicDataCustomPages{entity_name }PageName.aspx • To associate page template ListDetails.aspx with table Suppliers store it in – DynamicDataCustomPagesSupplier sListDetails.aspx
  18. 18. Custom Page Templates • Tipically, page markup contains DynamicField control – Concrete control for field is selected at runtime <Columns> <asp:DynamicField DataField=quot;CompanyNamequot; /> <asp:DynamicField DataField=quot;Phonequot; /> <asp:DynamicField DataField=quot;Faxquot; /> <asp:DynamicField DataField=quot;Productsquot; /> </Columns> • Dynamic Data Engine maintains consistent URLs – Name of the customized page has to coincide with the “built-in” page names (ListDetails.aspx, Edit.aspx, List.aspx, etc.) – Same URL used to access customized and uncustomized pages
  19. 19. Custom Field Template • It is possible to modify control associated with a datatype – Associate Calendar control with field of type Date • New templates can be assigned to “unknown” datatypes – Use Image control for binary field. • Custom Field Templates extend FieldTemplate UserControl • Property FieldValue retrieves field data <asp:Calendar ID=quot;Calendar1quot; runat=quot;server“ SelectedDate=quot;<%# (FieldValue!=null)? FieldValue:DateTime.Now %>quot; VisibleDate=quot;<%# (FieldValue!=null)? FieldValue:DateTime.Now %>quot; </asp:Calendar>
  20. 20. Custom Field Template-Edit Mode • Use ExtractValues() to write control data to DB protected override void ExtractValues(IOrderedDictionary dictionary) { dictionary[Column.Name] = ConvertEditedValue(Calendar1.SelectedDate.ToShortDateString()); }
  21. 21. MetaData application • Dynamic Data uses MetaData specified in the Data Model – But when model is regenerated changes are lost – Define additional metadata in partial class using System; using System.ComponentModel.DataAnnotations; [MetadataType(typeof(EmployeeMetadata))] public partial class Employee { } public class EmployeeMetadata { [UIHint(quot;DateTimeCalendarquot;)] public object HireDate { get; set; } }
  22. 22. Data Validation • Can use metadata public class CustomerMetadata { – [Required()] [Required()] public object Title; } – [Range(0,100)] • Using validation events (Local) • Pattern On<Field>Changing, On<Field>Changed public partial class Customer { partial void OnTitleChanging(string value) { if (!Char.IsUpper(value[0])) { throw new ValidationException( quot;Title must start with an uppercase letter.quot;); } } }
  23. 23. Data Validation • Using Validate event (Global) – OnValidate fires on change for any field – You can filter on type on change (ChangeAction) public partial class Employee{ partial void OnValidate(System.Data.Linq.ChangeAction action){ if (action == System.Data.Linq.ChangeAction.Insert)) { if (this._BirthDate.Value.CompateTo(DateTime.Now)>0) throw new ValidationException(“The birth date cannot be in the future”); } } }
  24. 24. Customization-DEMO
  25. 25. Dynamic Data Wizard • Facilitates creation of Dynamic Data web sites • In development – Not part of the .Net 3.5 SP1 RTM (not supported) – Downloadable from CodePlex – Requires SP1 of VS 2008 – Will not work with VS 2008 Express Ed.
  26. 26. Dynamic Data Wizard
  27. 27. Step1: Data Model • Data Model – New Data Model generation – Can select existing model
  28. 28. Step2: Choose Entities for the Model • Table selection • Can specify Namespace • Can specify class name ( “DataContext” is appended) • LINQ to SQL or LINQ to Entities
  29. 29. Step3: Page Template Selection • Wizard generates Custom Page Templates – Template for a list view (List) – for details (Details), adds Details link for each element in list view – For edition view (Edit) – New element (Insert)
  30. 30. Step4: Operation Customization • Select/Restrict operations type – edition, insertion, deletion, details • You can select fields for each view
  31. 31. Dynamic Data Wizard - Summary • Data Model is generated (DataContext) and the Page Templates • All Page Tempates go into CustomPages – Wizard does not use “standard” page templates • Can select Fields to appear in each View and types of operations
  32. 32. Dynamic Data Wizard - DEMO
  33. 33. Summary • Dynamic Data facilitates creation of data-driven web sites – Increases development productivity – Simplifies maintenance – Possibility of customization • Dynamic Data Wizard still under development
  34. 34. References • Introduction to ASP.NET Dynamic Data-Dynamic Data in Action Webcasts – http://www.asp.net/dynamicdata/ • Using ASP.NET Dynamic Data (MSDN) – http://msdn.microsoft.com/en-us/library/cc488545.aspx • Dynamic Data Futures (Source Code) – http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14475 • Dynamic Data Wizard (Template for VS 2008 SP1) – http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14474 • ASP .NET Dynamic Data (Video Links) – http://www.myvbprof.com/2007_Version/Dynamic_Data_Tutorial.aspx • ASP .NET Dynamic Data Attributes – http://blogs.msdn.com/mairaw/archive/2008/04/24/dynamic-data-attributes.aspx
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×