ASP.Net 3.5 SP1 Dynamic Data

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

3 comments

Comments 1 - 3 of 3 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

1 Favorite

ASP.Net 3.5 SP1 Dynamic Data - Presentation Transcript

  1. ASP.Net 3.5 SP1- Dynamic Data Michał Morciniec – GPSD Spain micham@microsoft.com
  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. 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. 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. Dynamic Data WebSite – Creation 1 • Use template “Dynamic Data Web Site” • Web Site Project contains “Dynamic Data” folder
  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. 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. 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. Dynamic Data-Creation DEMO
  10. Page Templates • Located in Dynamic Data\\Page Templates • Page Uses Controls- – DynamicDataManager – DynamicValidator – FilterRepeater – DynamicControl – DynamicField • GridView used to show data.
  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. Separate-Page Mode • Uses following route in Global.asax – {table}/{action}. • {action} can be – Edit routes.Add( – List new DynamicDataRoute(\"{table}/{action}.aspx\") { – Details Constraints = new RouteValueDictionary( new { action = \"List|Details|Edit|Insert\" }), – Insert Model = model }); • Every operation uses different page – No “in-line” editing
  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(\"{table}/ListDetails.aspx\") { Action = PageAction.List, ViewName = \"ListDetails\", Model = model }); routes.Add( new DynamicDataRoute(\"{table}/ListDetails.aspx\") { Action = PageAction.Details, ViewName = \"ListDetails\", Model = model });
  14. Page Modes combination • Each entity can use its Page Mode: • Order is significant routes.Add( new DynamicDataRoute(“Products/{action}.aspx\") { Constraints = new RouteValueDictionary( new { action = \"List|Details|Edit|Insert\" }), Model = model, Table = “Products” }); routes.Add( new DynamicDataRoute(\"{table}/ListDetails.aspx\") { Action = PageAction.List, ViewName = \"ListDetails\", Model = model }); routes.Add( new DynamicDataRoute(\"{table}/ListDetails.aspx\") { Action = PageAction.Details, ViewName = \"ListDetails\", Model = model });
  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 DynamicData\\FieldTemplates – “Intrinsic types”
  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. Custom Page Templates • Page Templates can be designed • They follow naming convention – DynamicData\\CustomPages\\{entity_name }\\PageName.aspx • To associate page template ListDetails.aspx with table Suppliers store it in – DynamicData\\CustomPages\\Supplier s\\ListDetails.aspx
  18. Custom Page Templates • Tipically, page markup contains DynamicField control – Concrete control for field is selected at runtime <Columns> <asp:DynamicField DataField=\"CompanyName\" /> <asp:DynamicField DataField=\"Phone\" /> <asp:DynamicField DataField=\"Fax\" /> <asp:DynamicField DataField=\"Products\" /> </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. 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=\"Calendar1\" runat=\"server“ SelectedDate=\"<%# (FieldValue!=null)? FieldValue:DateTime.Now %>\" VisibleDate=\"<%# (FieldValue!=null)? FieldValue:DateTime.Now %>\" </asp:Calendar>
  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. 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(\"DateTimeCalendar\")] public object HireDate { get; set; } }
  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( \"Title must start with an uppercase letter.\"); } } }
  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. Customization-DEMO
  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. Dynamic Data Wizard
  27. Step1: Data Model • Data Model – New Data Model generation – Can select existing model
  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. 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. Step4: Operation Customization • Select/Restrict operations type – edition, insertion, deletion, details • You can select fields for each view
  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. Dynamic Data Wizard - DEMO
  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. 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

+ michammicham, 2 years ago

custom

3731 views, 1 favs, 2 embeds more stats

In this presentation we will have a look at the Dyn more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 3731
    • 3666 on SlideShare
    • 65 from embeds
  • Comments 3
  • Favorites 1
  • Downloads 155
Most viewed embeds
  • 64 views on http://blogs.msdn.com
  • 1 views on http://www.slideshare.net

more

All embeds
  • 64 views on http://blogs.msdn.com
  • 1 views on http://www.slideshare.net

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories