We have model below for 10 buildings:
Buildings (EditableRootList) ---àFloors(EditableChildList) -----à Rooms(EditableChildList)
But, each time of Save() in folowing code, it creates a new record for the previous saved-records.
Anything I did wrong or I missed? (I did use CSLA extension for code generation)
buildingList = BuildingList.New();
for (int i = 0; i < 10; i++)
{
Building building = buildingList.AddNew(); //Add a new Building.
InitializeBuilding(building); //Initialize the newly added Building.
buildingList.Save(); //Suppose only Save the newly added to DB. But NOT.
}
Thanks for any suggestions…
HI,
#1: Make sure to set the proper state of yuor child objects. Default is IsNew. You must call MarkOld (or use the DataPortal to call DataPortal_XYZ methods) to mark the object as Existing.
#2: Finally - your code in Insert/Update method must decide whether or not to save the item based on the state (IsSelfDirty, IsNew, IsDeleted). F.ex: maybe you need to recalculate something based on a parent property even if the child itself did not change.
What is the code inside InitializeBuiding method?
Copyright (c) Marimer LLC