locked
grouping columns into class to pass into FieldTemplate sporadic problem RRS feed

  • Question

  • User-1266811045 posted

    Hi All,

     I'm new to Dynamic Data and am trying something a little strange. I wrote a custom FieldTemplate that expects a class data type. The class is just a grouping of the actual entity columns - I copy the columns into the class and return the instance in the class getter. In the class setter I update the actual columns with the new values. That's it. This works very well most of the time. However sometimes when I go to update, my class is updated to  the correct values - but the original properties are not. I stepped through with the debugger and when it does not work I can see the original properties getting set to the correct values and then immediately reset to something else. Again, this happens only sometimes. Sometimes it works properly. Any ideas as to what's going on?

     Thanks much.

    Tuesday, November 4, 2008 5:06 PM

Answers

All replies

  • User-330204900 posted

    I think you are doing something simlar to what I did as an example for an other post have a look at this: Dynamic Data Compound Column

    If it's not what you are doing let me know [:D]

    Wednesday, November 5, 2008 9:25 AM
  • User-1266811045 posted

    Hi Steve,

    Thanks for the reply. I am doing almost exactly what you did in the Compound Column. My class does not contain anything too complicated - just a couple of strings and bools and a date. Yet my db table, which is a large table with foreign keys, etc,  is still not getting updated correctly every now and then.

    When I update a plain column I see that the column setter gets hit 3 times - 1. change null to new value, 2. change null to old value, 3. change old value to new value. Looks like two instances of my table entity got created. Makes sense.

    When I update my custom class (and it's at the non-working stage) I see that the column (original - not my class) setter gets hit 5 times - 1. change null to new value, 2 change new value to null, 3. change null to old value 4. change old value to null  5. change null to null so do nothing. OnCreated gets hit multiple times, more than the two that I would expect.

    I'm  trying to figure out what causes steps 2 and 4 happen...

    Wednesday, November 5, 2008 1:14 PM
  • User-1266811045 posted
    With a bit more research it looks like LINQ thinks there's a concurrency conflict going on...
    Wednesday, November 5, 2008 3:33 PM
  • User-1005219520 posted

    Hey mkaty,

    Would it be possible to come up with the simplest possible repro and post it here? Bonus points if you use NorthWind or AdventureWorks DB - Or just a couple simple tables and the T-SQL to create/populate them.

    Thursday, November 6, 2008 12:03 AM
  • User-1266811045 posted

    Here are the bits of code (in bold) I added to the DynamicDataFutures sample to reproduce the problem. If I add UpdateCheck=UpdateCheck.Never to the attributes for the 3 columns concerned the update works every time.

    NorthwindPartials.cs:

        [Serializable]
        public class CombinedColumns
        {
            private string _firstName;
            private string _lastName;
            private System.DateTime? _hireDate;
    
            public CombinedColumns(string first, string last, System.DateTime? date)
            {
                _firstName = first;
                _lastName = last;
                _hireDate = date;
            }
    
            public string firstName { get { return _firstName; } set { _firstName = value; } }
            public string lastName { get { return _lastName; } set { _lastName = value; } }
            public System.DateTime? hireDate { get { return _hireDate; } set { _hireDate = value; } }
        }
    
        [MetadataType(typeof(Employee_MD))]
        public partial class Employee {
         public CombinedColumns MyCombinedColumns
           {
                get
                {
                    return new CombinedColumns(this.FirstName, this.LastName, this.HireDate);
                }
                set
                {
                    if (value != null)
                    {
                        CombinedColumns cc = (CombinedColumns)value;
    
                        this.FirstName = cc.firstName;
                        this.LastName = cc.lastName;
                        this.HireDate = cc.hireDate;
                    }
                }
            }
    
            public class Employee_MD {
    
                [UIHint("CombinedColumns")]
                public object MyCombinedColumns { get; set; }
                [DataType(DataType.Url)]
                public object PhotoPath { get; set; }
            }
        }
    CombinedColumns_Edit.aspx.cs  - the aspx just has the 3 textboxes with labels
        public partial class CombinedColumns_EditField : System.Web.DynamicData.FieldTemplateUserControl {
            protected void Page_Load(object sender, EventArgs e) {
            }
    
            protected override void OnDataBinding(EventArgs e)
            {
                base.OnDataBinding(e);
    
                CombinedColumns cc = (CombinedColumns)this.FieldValue;
                if(cc != null)
                {
                    TextBox1.Text = cc.firstName;
                    TextBox2.Text = cc.lastName;
                    TextBox3.Text = (cc.hireDate ?? DateTime.Now).ToShortDateString();
                }
            }
    
            protected override void ExtractValues(IOrderedDictionary dictionary) {
    
                CombinedColumns cc = new CombinedColumns(TextBox1.Text, TextBox2.Text, DateTime.Now);
                dictionary[Column.Name] = cc;
            }
    
        }
     

    Added Custom Edit Page for the Employees table: only change to DetailsView1 is AutoGenerateRows = false and the only DynamicField is MyCombinedColumns.

    <?xml:namespace prefix = asp /><asp:DetailsView class=st id="
    <asp:DetailsView class=st id="            </FIELDS>
                </asp:DetailsView>
      </asp:DetailsView>
     
    Thursday, November 6, 2008 12:06 PM
  • User-1005219520 posted

    Thanks - I'll work on this and report back what I find out.

    Thursday, November 6, 2008 12:23 PM
  • User-1005219520 posted

    Hey mkaty,

    I talked to our architect and he suggested another approach. Please see the DoubleColumn.zip sample  at http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 7, 2008 3:37 AM
  • User-1266811045 posted

    Thanks for checking this out Rick. Much appreciated.

    Friday, November 7, 2008 2:26 PM