ASP.NET Dynamic Data editing Complex Objects

I'm working on a ASP.NET Dynamic Data web site with a Linq to SQL Database Context and I have a question. In one of my tables, ARReports, exists a column with raw XML data which I can deserialize into a ReportDetails object, along with other data such as EditedBy, ReleaseDate, and other fields.

ReportDetails has several public properties which I would like to expose on my custom Edit.aspx page.

My goal is: when a user navigates to the Edit.aspx page, I want them to be able to edit the ARReports row and the public properties of ReportDetails, all of which are primative types. Then when they update: serialize the ReportDetails object back into XML and update that field in the table.

Is there anyway I can say, create a Property in the ARReport class (the Linq to SQL class) of type ReportDetails, and have that class scaffold into the Edit.aspx page? Maybe something that looks like this:

public partial class ARReport
{
    private ReportDetails _details;

    public ReportDetails Details
    {
         get
         {
             if (_details == null)
                  _details = ReportDetails.DeSerialize(this.RawXML);
             return _details;
         }
         set
         {
             this.RawXML = ReportDetails.Serialize(_details);
         }
}

public class ReportDetails
{
     public String Owner {get; set;}
     public DateTime LastEdit {get; set;}
     //...etc...

     public static String Serialize(ReportDetails report)
     {
          // serialization code
     }

     public static ReportDetails DeSerialize(String rawXML)
     {
         // deserialization code
     }
}

I am hoping there is some combination of Attributes and/or tricks I can apply to the classes and properties to achieve what I am looking for but so far, a rigorous google search has not presented any solutions. I hope this wasn't too confusing. I appreciate any help or insight.

Answers


This can be done. Consider keeping the properties of the ReportDetails OUT of the L2S data context (since it is not explicitly in your DB except as one column).

What I would suggest is building a custom field template for the Report Details. Use UIHintAttribute to reference that field template properly on the Edit/Details pages. Before populating the control, deserialize the report details into a POCO and fill in the control as per usual..

As far as serialization, in the datacontext override the SubmitChanges event, check for Updates to the ARReport, change the property value, and then submit changes:

public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
{
    ChangeSet changeset = GetChangeSet();
    foreach (var change in changeset.Updates.OfType<ARReport>())
    {
        // serialize ReportDetails here before submitting changes. 
    }   
    try
    {
        base.SubmitChanges(ConflictMode.ContinueOnConflict);
    }
    catch (ChangeConflictException cce)
    {
        // handle this
    }
}

Need Your Help

MySQL select 1 row from inner join

mysql select row limit

I'm don't know the terms for this problem, the title might be a little bit misleading.