CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Child in RootList is saved when it is unchanged.

rated by 0 users
Not Answered This post has 0 verified answers | 1 Reply | 1 Follower

Not Ranked
6 Posts
TF Zheng posted on Mon, Jul 2 2012 11:29 PM

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…

All Replies

Top 10 Contributor
1,815 Posts

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?

Jonny Bekkum, Norway CslaContrib Coordinator

Page 1 of 1 (2 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems