Reputation: 105
I'm having some trouble determining when to use the e.Row properties or cache.SetValue/SetValueExt when updating the value of a record. In the T200 course, there's a portion from the pdf that says,
To update a field that is defined after the current field in the data access class, use the properties of the e.Row data record as follows.
ShipmentLine line = e.Row as ShipmentLine;
...
line.Description
To update a field that is defined before the current field in the data access class, use the SetValueExt<>() method:
sender.SetValueExt<ShipmentLine.ProductID>(e.Row, GiftCardID);
In these cases, what are they referring to when they say "before" and "after"? If my DAC field declaration is in the order below:
Field1 {get;set;}
Field2 {get;set;}
Field3 {get;set;}
Do they literally mean, if I'm in "Field2.FieldUpdated()" I would have to update Field1 and Field3 like so?
sender.SetValueExt<ShipmentLine.Field1>(e.Row, "X");
line.Field3 = "X";
Also, are there some hard rules on when to use which method? I.e. if in a RowUpdated event, use "X", if in a FieldUpdated event, use "Y".
Upvotes: 3
Views: 885
Reputation: 8268
You will encounter mainly three types of assignment:
1. record.Field = "value"
2. cache.SetValue<T>
3. cache.SetValueExt<T>
Method 1 and 2 are essentially the same. They assign the value without raising events. The practical difference is that with method 2 you can avoid a cast.
// 1. With cast
ShipmentLine line = e.Row as ShipmentLine;
if (line != null)
{
line.Description = "value";
}
// 2. Without cast
sender.SetValue<ShipmentLine.description>(e.Row, "value");
SetValueExt should be used when you want the assignment to raise FieldUpdated events. Many fields on UI are raising events when user changes their value. If user changes the quantity fields of a sales order it will raise FieldUpdated events which will in turn re-compute the total price.
If you were to change the quantity programmatically from code you should use SetValueExt as it will ensure re-computing the total cost using the events system. It is especially useful when you try to replicate what a user would do on screen since UI controls all raise events by default.
Upvotes: 6