160 likes | 277 Views
RAD Web Applications with ASP.NET Dynamic Data. Ingo Rammer ingo.rammer@thinktecture.com. Ingo Rammer and thinktecture . Support and consulting for software architects and developers Application Optimization, Troubleshooting, Debugging Architectural Consulting and Prototyping
E N D
RAD Web Applications with ASP.NET Dynamic Data Ingo Rammeringo.rammer@thinktecture.com
Ingo Rammer and thinktecture • Support and consulting for software architects and developers • Application Optimization, Troubleshooting, Debugging • Architectural Consulting and Prototyping • Developer-Coaching and -Mentoring • Architecture and Code Reviews • http://www.thinktecture.com • ingo.rammer@thinktecture.com
ASP.NET Dynamic Data • Customizable model/class-driven frontend technology • Today: Linq-to-SQL and Entity Framework • Scaffolding • Highly customizable • But more important: • Dynamic Data Controls
Customizable Scaffolding • Scaffolding – Automatic Form Generation • Customizable UI („No Limits“ – it‘s all .NET) • Configurable MVC-style URL routing • Default: Querystring, but can be changed to routing like: • http://server/Customers • http://server/Customers/ALFKI • http://server/Customers/ALFKI/Edit • ... or any other routing you can imagine
Extensibility • Extension Model for logical schema (Entity Framework or Linq-to-SQL) • Validation • Business Rules • Sorting, Filtering, Edit, Insert, Delete • .NET Framework 3.5 SP1 (+ Hotfix)
Scaffolding • The first thing you‘ll see at every demo • Zero code data forms (but still: customizable whenever you want!) • Simply uncomment the following line • This enables scaffolding for all entities // Global.asax in Application_Start model.RegisterContext (typeof(NorthwindEntities), new ContextConfiguration() { ScaffoldAllTables = true });
Restricted Scaffolding • Attributes on a class-level or field level • Field level supports metadata-redirection with [MetadataType] [ScaffoldTable(true)] [MetadataType(typeof(ProductsMetaData))] public partial class Products { } public class ProductsMetaData { [ScaffoldColumn(true)] public object Name; }
Customizating Templates • Templates • Page Templates („all List Pages“, „all Detail pages“) • Field Templates („all Integer TextBoxes“) • Custom Pages • Use a particular ASP.Net page for List,Detail,Edit and/or Insert • Can be done globally or configured with routing • Can use DynamicField/DynamicControl with UIHints on them
Creating a Custom Page • Simply create a folder in CustomPages named like your entity and copy/paste one of the existing ASPX pages • Create a folder name with the exact same name as your entity class • Copy and paste the desired ASPX file from PageTemplates to CustomPages/EntityName • Done! (no configuration necessary)
Sample Custom Page <asp:DetailsView DataSourceID="DetailsDataSource" AutoGenerateRows="false"> <Fields> <asp:DynamicField DataField="ProductName" /> <asp:DynamicField DataField="QuantityPerUnit" HeaderText ="Quantity" /> <asp:DynamicField DataField="UnitPrice" /> <asp:DynamicField DataField="UnitsInStock" /> <asp:DynamicField DataField="Categories" /> <asp:TemplateField> <HeaderTemplate>Name</HeaderTemplate> <ItemTemplate> Templated: <asp:DynamicControl runat="server" DataField="ProductName" /> </ItemTemplate> </asp:TemplateField> </Fields> <asp:DetailsView>
Customizing the Model • [UIHint]: Use a certain control for a field • [DataType]: custom type (it’s just a string) which can later be used by the field template („EmailAddress“, „Url“) • [DisplayFormat]: Use a certain format string for one field • [DisplayField]: Use this column for foreign key values of this table (ex: display the field „Name“ for Customers) • And more: Whatever you want/need to later check in a custom input control. Create custom Attributes as needed
Custom Fields • Create a ASCX in /FieldTemplates, derive from FieldTemplateUserControl and override DataControl • Possible: • Override FormatFieldValue, ExtractValues • Use MetaDataAttribute. TypeOf<T>() to get access to attributes defined on the field in the model
Embedding DD • Using DynamicData on an unrelated ASPX page • Hint: It's just like the custom page! • Create a DataSource, Parameters, DetailView, GridView or ListView and you're ready to go ...
In-Depth Customization • There are hardly any limits, DD fits very nicely with ASP.NET • You‘ve already seen: custom fields, custom pages • Missing pieces is: which fields get displayed, in what order? • IAutoFieldGenerator: specifies which fields should be displayed
Future • Preview can be downloaded (ASP.NET Dynamic Data 4.0 Preview 2) • Different data access layers • ASP.NET Data Services & custom data layers • Query Blocks • Filtering with LINQ Expressions • Additional Field Templates (Enum, Email, Url)