RE: Child in Root List is saved when is unchanged.

Jul 2, 2012 at 11:39 PM

Budimir,

We have model below for 10 buildings:

Buildings (EditableRootList) ---àFloors(EditableChildList) -----à Rooms(EditableChildList)

But, each time of Save(), it creates a new record for the previous records.

Anything I did wrong or I missed?

Thanks for any suggestions…

Ting

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 Building to DB. But NOT.

}

Coordinator
Jul 3, 2012 at 8:42 AM

Hi Ting.

Please check CSLA documentation:

When saving business object you must assign the result of the Save method to your local variable. So your code should look like this (red line):

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 = buildingList.Save(); //Suppose only Save the newly added Building to DB. But NOT.


}

 

Btw, this looks a bit suspicious to me; you have an EditableRootList and save each item separately.