field mapped on related field not restored with Rollbackfields

Posts   
 
    
Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 26-Sep-2005 22:33:26   

Hello,

I have the following structure:

TravelFile: startdate, enddate, supplierid and suppliercompanyname

suppliercompanyname is a field mapped on a related field. There is a relation between TravelFile and Suppliers through the supplierid field.

When I use this entity to update information and I use SaveFields to save the values of the fields before I update the object, modify the values of the object, including the supplierid and then call Rollbackfields, all fields are correctly rolled back, including the supplierid, but the value of the field suppliercompanyname is not updated.

How can I solve this without recalling the data from the database?

Thx, Bernaert Dominique.

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 27-Sep-2005 04:41:29   

Bernaert,

Please post an example of your code and specify which version of LLBLGen you're using.

Thanks

Paul

Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 27-Sep-2005 08:49:25   

Ok,

I have a collection of TravelFileblocs, which are linked to a TravelFile, when I hit the edit button, I call the following code which displays an update screen. If the user hits the cancel button, I check the value of recordadded and I restore the previous values with the code below. This works great for all fields that are in the entity, but not on the field mapped on a related field.


int recordindex = BindingContext[fileEntry.Travelfileblocs].Position;
if (recordindex < 0)
    return;

TravelAgent.Dal.EntityClasses.TravelfileblocsEntity bloc = new TravelAgent.Dal.EntityClasses.TravelfileblocsEntity();
bloc = fileEntry.Travelfileblocs[recordindex];
if (bloc != null)
{
    bloc.SaveFields("BeforeUpdate");
    TravelFilesFreeBlocAdd blocadd = new TravelFilesFreeBlocAdd();
    blocadd.blocEntry = bloc;
    blocadd.Call_modify_bloc();
    if (blocadd.recordadded == true)
    {
        uow.AddForSave(blocadd.blocEntry);
        fileEntry.Travelfileblocs.SupportsSorting = true;
        fileEntry.Travelfileblocs.Sort((int)TravelAgent.Dal.TravelfileblocsFieldIndex.Bloctitle, ListSortDirection.Ascending);
    }
    else
    {
        bloc.RollbackFields("BeforeUpdate");
        fileEntry.Travelfileblocs.SupportsSorting = true;
    }
    blocadd.Dispose();

Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 27-Sep-2005 09:29:16   

The version I'm using is 1.0.2004.2 Final (August 5th, 2005)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Oct-2005 12:09:08   

This isn't supported currently. What you want is 'graph versioning', e.g.: the versioning of a graph of related entities at a given point in time, so when you modify any entity in that graph from that point, you can roll back that graph later on to the state you saved earlier.

You can 'work around' this by also saving the fields in teh related entity and roll them back as well.

Frans Bouma | Lead developer LLBLGen Pro
Dominique
User
Posts: 22
Joined: 13-Sep-2005
# Posted on: 13-Oct-2005 15:31:46   

Hello,

I've tried like you said, but it does not seem to work. I get the following error: No saved fields were found under the name 'Supplierbeforeupdate'.

This is the code:

int recordindex = BindingContext[fileEntry.Travelfileblocs].Position; if (recordindex < 0) return;

TravelAgent.Dal.EntityClasses.TravelfileblocsEntity bloc = new TravelAgent.Dal.EntityClasses.TravelfileblocsEntity(); bloc = fileEntry.Travelfileblocs[recordindex]; if (bloc != null) { bloc.SaveFields("BeforeUpdate"); bloc.Blocrelatedsupplier.SaveFields("Supplierbeforeupdate"); if (bloc.Bloctype == "1") { TravelFilesFreeBlocAdd blocadd = new TravelFilesFreeBlocAdd(); blocadd.blocEntry = bloc; blocadd.Call_modify_bloc(); if (blocadd.recordadded == true) { uow.AddForSave(blocadd.blocEntry); fileEntry.Travelfileblocs.SupportsSorting = true; fileEntry.Travelfileblocs.Sort((int) TravelAgent.Dal.TravelfileblocsFieldIndex.Bloctitle, ListSortDirection.Ascending); } else { bloc.RollbackFields("BeforeUpdate"); bloc.Blocrelatedsupplier.RollbackFields("Supplierbeforeupdate"); fileEntry.Travelfileblocs.SupportsSorting = true; fileEntry.Travelfileblocs.Sort((int)TravelAgent.Dal.TravelfileblocsFieldIndex.Bloctitle, ListSortDirection.Ascending); } blocadd.Dispose(); } }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Oct-2005 21:52:13   

Could it be the related entity got changed / replaced by another instance/entity as you're performing db activity as it seems?

Frans Bouma | Lead developer LLBLGen Pro