Friday, April 11, 2008

ASP.Net Dynamic Data Support

What ASP.Net Dynamic Data support does?


  • Automatically renders fully functional editable pages that are dynamically constructed from your ORM data model ('Linq to Sql' or 'Linq to Entity') meta-data.

  • Provides automatic UI validation support based on the constraints set on your data model classes from the database, if not modified by you. These data constraints can be modified by extending a model class (implementing its partial class). No need to put validation checks in aspx code.
Following snippet validates product name and
renames column UnitsInStock and defines range for it.

[MetadataType(typeof(Product_MD))]
public partial class Product
{
partial void OnProductNameChanging(string value)
{
if (value[0] == 'a')
throw new Exception("Must not start with a");
}
}

public class Product_MD {
[DisplayName("My units")]
[Description("This number shows how many unites are left")]
[Range(0, 150, ErrorMessage = "Incorrect range for the units in stock")]
public object UnitsInStock { get; set; }
}

The Product_MD is an extra class, the reason why it is here is that there is no way to add attributes to properties defined on the other side of the partial class (which is the generated model file).

  • Provides support for modifying field/page templates and also integrating third party templates (both field and page level) very easily.
Following snippet shows how to apply 'Dbimage' field template on picture column of Category table
[MetadataType(typeof(CategoryMetadata))]
public partial class Category
{
}

public class CategoryMetadata {
[UIHint("DbImage")]
public object Picture { get; set; }
}

Here Scott Hunter's talks about adding image support using DD field templates support.

  • Watch this Video presented at MIX 08 for detailed introduction of Dynamic Data Support Feature.
  • Also David Ebbo's blog mentions changes between Dynamic Data December Preview and April Preview.


No comments: