Sql – How to edit a SQL Server XML data field with asp.net Dynamic Data

asp.netdynamic-datascaffoldingsql-serverxml

I have a site based around asp.net 3.5's Dynamic Data feature. Everything's working great, but I would like to add a tagging feature via a column with an XML data type. I've made the column and added an appropriate schema, but it is showing up as read-only and the scaffold will not display or modify the field.

So, I have a few questions:

  1. What do I need to do in order to enable my scaffold to see this xml column?
  2. How would I go about editing the tags through the scaffold without directly editing all the xml?
    • Would I add logic to the getter/setter in the metadata?
    • Presumably I would need a custom fieldTemplate, would I add the xml parsing to it?

Best Solution

I hope this is helpful. As you mention, you would have to create a field template for your XML data. :

[MetadataType(typeof(DocumentMetadata))]
[DisplayName("Documents")]
public partial class Document {

    [ScaffoldColumn(true)]
    [Display(Name = "Some Xml")]
    public string SomeXml
    {
        get
        {
            return "<note><to>Joe</to><from>Mary</from><heading>Reminder</heading><body>Hello World</body></note>"
        }
    }
}

public class DocumentMetadata
{
    [ScaffoldColumn(false)]
    public object Id { get; set; }

    [Display(Name="Type")]
    public object DocumentType { get; set; }

    [UIHint("CustomXmlFieldTemplate")]
    [Display(Name="Some XML")]
    public object SomeXml { get; set; }
}