Initialize new children with FK valuesInitialize new children with FK values
Old forum URL: forums.lhotka.net/forums/t/6433.aspx
Antonio Sandoval posted on Monday, February 16, 2009
I had writen a code generator, this generator add StringRequiered validation Rules for each Field that is not nullable. So I have a Root Parent and a Child list, when I add a new child its never come valid because the foreign key value is initialized in the update method. I write the foreign keys initializer in the ListChanged delegate, but I'm not sure if it will kill perfomance in bigger lists, or if there is a better way.
class RootParent : Bussinesbase{
private ChildList _ChildList =ChildList.NewChildList();
_ChildList_ListChanged(sender, e){
if(e.ListChangedType == ItemAdded){
foreach(Child c in _ChildList){
if(c.IsNew)
c.ForeignKey = _Primarykey; <-Initialize all of the foreign keys
}
}
}
DataPortal_Update(){
DoInsertUpdate();
_ChildList.Update(this);
}
}
class ChildList : BussinesListBase {
addValidationRules(){
AddStringRequiered("ForeignKey");
}
internal Update(RootParent parent){
foreach(Child c in this){
c.ForeignKey = parent.PrimaryKey;
if(c.IsNew)
c.Insert();
else
c.Update();
}
}
}
Copyright (c) Marimer LLC