ORMEntityOutOfSyncException - User Control with Entity, trying to use to track changes to inner collections

Posts   
 
    
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 17-Jan-2007 04:16:13   

I've been trying to get this senario to work to no avail:

I have a LocationEntity which has N related UnitEntity's. I have a User Control which allows you to select a LocationEntity and create a UnitEntity along with several other collections related to LocationEntity.

I want to be able to hold the created UnitEntities in a Collection until the user clicks "Save" but if I try to bind this Collection to a display to allow the user to further control the Collection until pressing "Save" I get an ORMEntityOutOfSyncException. I understand that the Entity is outofsync and this error is by design but I need some simple solution in order to achieve for result I'm aiming for. An example would be great. Thanks.

Oh - using Adapter with Manager Templates btw

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Jan-2007 07:30:56   

I'm not completely sure how do you handle this.

Please post: 1- the runtimeLibrary version which you are using. 2- Code snippets.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Jan-2007 16:58:57   

You save manually using a dataaccessadapter or via a datasourcecontrol? Because when saving, please specify you want to refetch the entity in the save method you're calling.

Frans Bouma | Lead developer LLBLGen Pro
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 21-Jan-2007 08:01:30   

I guess there are two questions:

1) Im trying to develop a set of user controls with a property such as EntityCollection<OrderEntity>. Im persisting the entities using ViewState between postbacks and I have a form which allows the user to enter the details of a Customer entity along with its related Orders entities. I am capturing the Customer Entity OrderEntities and their related sub entities (x number of OrderItem, x number of OrderItemAmenities) before actually doing a save to database. When I try to restore the collections of the CustomerEntity I receive the out of sync exception. The only work around i've found is to save the CustomerEntity but that will only allow me to work with the first set of related entities as i mention. If the entities which are children of Customer have children themselves OrderEntity - OrderItem, these inner collections won't persist but I guess I should have figured as much if i needed a to persist the parent entity in the first place.

I'd prefer not to have to commit any change to the database until the user has "checked out". I guess the question is if I use List<EntityHere> instead of EntityCollection<EntityHere> here will it not give the exception. I havent tried but that will be next. As an example of just one of the controls in the hirearchey being added to the controls inner collection.


//retreives from controls viewstate or instantiates new collection control
EntityCollection<OrderEntity> orders = this.OrderCollection;

//OrderControl.SelectedEntity returns a new OrderEntity with its fields 
//set according to the values on the controls surface (set by user)
orders.Add(OrderControl.SelectedEntity);

orders = this.OrderCollection;
BindOrderCollection();

2) after using a data access adapter to save and setting refetch to true, it seems like i'm losing my "prefetch path" data.


OrderManager.Save(order, true);

Console.WriteLine(order.OrderItem.Count.ToString()) 
//returns 0 but database has saved related OrderItems)

BTW-using ManagerTemplates and of course Adapter

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 21-Jan-2007 23:41:29   

If I read you right, you're trying to add items to a collection between postbacks, but only persist the entire collection to the database when the user clicks "Save". Is this correct?

KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 22-Jan-2007 20:13:08   

Yes thats correct. Also the entities placed in this collection have collections themself of smaller entities (i.e OrderEntity being placed in viewstate collection has property exposing collection of OrderItem, these order items only exist in memory).

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Jan-2007 07:51:56   

How do you save your collection in the view state? Are you using an LLBLGenProDataSource?

I am capturing the Customer Entity OrderEntities and their related sub entities (x number of OrderItem, x number of OrderItemAmenities) before actually doing a save to database. When I try to restore the collections of the CustomerEntity I receive the out of sync exception

Please post the complete related code snippet.

And what do you mean by "When I try to restore the collections of the CustomerEntity I receive the out of sync exception"?

Does this happen after the database save?