Wednesday 18 June 2008

ASP.NET Dynamic Data - New Feature in ASP.NET 3.5 SP1

After attending NxtGenUG Fest 08 last week in my old office at Microsoft UK HQ, Thames Valley Park, I was particularly excited to hit the ground running with a topic presented by Dave Sussman, ASP.NET Dynamic Data.

This is a new feature in the yet to be released SP1 for .NET 3.5. (A beta is available here - this is pre-release so use on a VM or spare machine)

Dynamic Data is a scaffolding framework - what does this mean? Well this is how Scott Guthrie describes it:

.NET 3.5 SP1 adds support for a rich ASP.NET data "scaffolding" framework that enables you to quickly build functional data-driven web application. With the ASP.NET Dynamic Data feature you can automatically build web UI (with full CRUD - create, read, update, delete - support) against a variety of data object models (including LINQ to SQL, LINQ to Entities, REST Services, and any other ORM or object model with a dynamic data provider).

SP1 adds this new functionality to the existing GridView, ListView, DetailsView and FormView controls in ASP.NET, and enables smart validation and flexible data templating options. It also delivers new smart filtering server controls, as well as adds support for automatically traversing primary-key/foreign-key relationships and displaying friendly foreign key names - all of which saves you from having to write a ton of code.

I think of this scaffolding framework as DataBinding 2.0 - to get a good idea of what Dynamic Data is, I recommend watching this video from David Ebbo.

Now, the awesome thing about Dynamic Data is that it doesn't have to work on just a Data Model generated from a database or LINQ datasource. It can work against a business object using the ObjectDataSource approach - this is an amazing ability to save time getting features such as validation, column typing, display names and descriptions etc piped into your application for free.

For an integration project I have been working on where I generate business objects using an ASP.NET build provider, and then databind them against custom controls, I can now get rid of the following things:
  • A proprietary ValidationFramework
  • Custom column type mappings
  • Custom attributes on my business objects
  • Custom BoundFields
  • Custom DetailsView and GridView controls (which use the mappings and custom BoundFields)
...and instead I simply modify the build provider to decorate my class with the expected Dynamic Data attributes, and use the "DynamicObjectDataSource" from the latest samples pack.

Example business object:

public class NewData {
  [RegularExpression(@"[A-Z].*", ErrorMessage="The name must start with an upper case character")]
  [DisplayName("The name")]
  public string Name { get; set; }

  [Range(0, 1000)]
  public int Number { get; set; }

  public DateTime Date { get; set; }

Here is the ASPX declaration:

<asp:ValidationSummary ID="ValidationSummary1"
  HeaderText="List of validation errors" />

<asp:dynamicvalidator runat="server"

<asp:DetailsView ID="DetailsView1"

<asp:DynamicObjectDataSource ID="ObjectDataSource1"
  runat="server"   DataObjectTypeName="DynamicDataExtensionsSample.NewData"

...from that, a DetailsView control loads showing the correct data, using the correct client side controls (which can be completely customised) based on the data type, with enforced validation using automatically generated validators.

Now for some handy links:

Dynamic Data Website
Dynamic Data Forum
MSDN Documentation

This really is an awesome new technology. Expect to see more about this on my blog soon.

Many thanks to David Ebbo from the ASP.NET team for helping me out with Dynamic Data.

Tuesday 10 June 2008

What Do We Think of iPhone 3G?

iLounge have added a useful article on the new iPhone 3G.

I will be upgrading simply because I'm unable to say no to shiny new gadgets, especially when they combine: Apple, Internet, Email, Development Opportunities & Phone! - It's simply impossible for me to not buy this device! Yes - I know, I'm reminded how geeky this is by Mrs Meineck often!

Image: Courtesy of Apple

Looking at it with a more balanced head, in terms of new features iPhone 3G is an evolution not a revolution - but this evolution will IMHO help it transform from being the shiny gadget of a few lucky and cash-happy geeks to a device that will permeate through the enterprise and be very popular on the street.

Despite this, there are some embarrassing areas of lacking:
  • Proper Bluetooth implementation - why cant we send and receive pictures with each other? Yes e-mail allows sharing of photos but a large number of my friends don't have e-mail configured on their phones, and often we like to share photos down the pub, bar etc.
  • Why doesn't it support stereo Bluetooth - this is such an obvious feature for the latest iPod device.
  • Better camera - from the keynote it was obvious that the sample images they used must have been taken on some fantasy uber iPhone because with the current camera there is no way you could get that sort of quality. 2MP was good 10 years ago, but the camera is shocking compared to even 2005's standards of auto focus low light sensitive camera phones.
  • MMS - Sure MMS is a costly technology compared to sending an email with attachments - but why cant I at least receive MMS messages natively without having to log in to a cumbersome website, not even optimised for the smaller screen? Lots of my friends send MMS because their phones aren't setup for e-mail, and MMS works well for them.
  • Storage - 8GB and 16GB were a bit disappointing - but only because this isn't an improvement on the previous models.

Also amusing/depressing to note that BBC NewsBeat this morning reported the iPhone 3G as thinner, because in the keynote it was reported as “thinner at the edges”, when actually it is thicker overall but has tapered edges which are thinner. They also reported that it comes with Sat Nav - when actually it only comes with GPS enabled Google maps, which although supporting directions isn't exactly the sophisticated Sat Nav like TomTom. (I don’t expect this out of the box, and know it's on the cards from third parties as additional premium software, just annoyed to hear the BBC report so shabbily).

Oh well, you will still see me in the queue on July 11th!

read more | digg story