Definitely the problem is in mmBusinessObjectGeneric.PopulateForeignKeyField(). In the call to
this.PopulateKeyField(this.ForeignParentKeyField, this.ParentKeyValue)
this.ParentKeyValue is 0! Should be the, well the parent object's primary key value I would think.
Now, where is that supposed to get set...? Looks like mmBusinessObject.StateChangeHandler.
Ok, this is odd. That fires for the Parent object, but never for the child object. Where does that get assigned? Here it is in mmBusinessObject.RegisterChildBizObj()
this.StateChange += new mmBusinessStateChangeDelegate(childObject.StateChangeHandler);
Might this be the problem? In mmBusinessObjectGeneric.SaveEntity(), the PopulateForeignParentKeyField() is called
before the PreSaveEntityProcessing() (which calls the OnStateChange that actually sets the ParentKeyValue.
this.PopulateForeignParentKeyField();
if (this.PreSaveEntityProcessing(entity))
...
What happens if I force a PopulateForeignParentKeyField() after the PreSaveEntityProcessing()?
Ugh, I'd have to recompile MM.Net. Trying a few things but I think I'm onto something here....
Eric
>>Coincidentally, I'm having the exact same problem but only when trying to save new children. Existing ones save fine. The problem seems to be that the foreign key is not populating (a record does get saved, just with no foreign key). Is the syntax right, in that we just have to name the field or is there more needed?
>>
>>I've run through the debugger and get down the SaveChildObjects() and PopulateForeignKeyField() and the value that it's trying to save is zero, rather than the parent object's primary key value.
>>
>>Eric
>
>Hmm, I seem to remember a similar post awhile back. I wonder if there is some combination that causes that problem and Kevin had chimed in. Might should do a search here in this forum to see if that message is the same issue.
>Tim