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.
Please don't forget to let everyone
know what the solution is by marking
helpful responses as ANSWER.
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...
Please don't forget to let everyone
know what the solution is by marking
helpful responses as ANSWER.
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.
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
Added Custom Edit Page for the Employees table: only change to DetailsView1 is AutoGenerateRows = false and the only DynamicField is MyCombinedColumns.
Please don't forget to let everyone
know what the solution is by marking
helpful responses as ANSWER.
Member
81 Points
27 Posts
grouping columns into class to pass into FieldTemplate sporadic problem
Nov 04, 2008 05:06 PM|mkaty|LINK
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.
know what the solution is by marking
helpful responses as ANSWER.
All-Star
17915 Points
5680 Posts
MVP
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 05, 2008 09:25 AM|sjnaughton|LINK
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]
Dynamic Data Custom Pages
Always seeking an elegant solution.
Member
81 Points
27 Posts
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 05, 2008 01:14 PM|mkaty|LINK
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...
know what the solution is by marking
helpful responses as ANSWER.
Member
81 Points
27 Posts
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 05, 2008 03:33 PM|mkaty|LINK
know what the solution is by marking
helpful responses as ANSWER.
Star
12522 Points
2214 Posts
Microsoft
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 06, 2008 12:03 AM|ricka6|LINK
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.
Member
81 Points
27 Posts
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 06, 2008 12:06 PM|mkaty|LINK
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:
Added Custom Edit Page for the Employees table: only change to DetailsView1 is AutoGenerateRows = false and the only DynamicField is MyCombinedColumns.know what the solution is by marking
helpful responses as ANSWER.
Star
12522 Points
2214 Posts
Microsoft
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 06, 2008 12:23 PM|ricka6|LINK
Thanks - I'll work on this and report back what I find out.
Star
12522 Points
2214 Posts
Microsoft
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 07, 2008 03:37 AM|ricka6|LINK
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.
Member
81 Points
27 Posts
Re: grouping columns into class to pass into FieldTemplate sporadic problem
Nov 07, 2008 02:26 PM|mkaty|LINK
Thanks for checking this out Rick. Much appreciated.
know what the solution is by marking
helpful responses as ANSWER.