Self-Servicing reload collection after save

Posts   
 
    
llblstc
User
Posts: 19
Joined: 06-Jul-2009
# Posted on: 12-Jan-2011 13:12:27   

EntityCollection col = new EntityCollection (); col.add(new Entity()); col.add(new Entity()); col.add(new Entity()); col.save();

How do I reload the whole collection, so the entities reflects any trigger modifications?

I do not want to call Refetch on all elements

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2011 16:00:57   

In SelfServicing: When saving an entity, it will be refetched automatically if one of its fields were accessed.

The following is from the docs.

Setting the EntityState to Fetched automatically after a save By design an entity which was successfully saved to the database gets as EntityState OutOfSync. The LLBLGen Pro runtime framework will refetch an entity which is marked OutOfSync automatically right before an entity field's property is read. This is done to make sure that default constraints, calculated fields and elements which could have been changed after the save action inside the database (for example because a database trigger ran after the save action) are reflected in the entity after the save action. If you know that this won't happen in your application, you can get a performance gain by specifying that LLBLGen Pro should mark a successfully saved entity as Fetched instead of OutOfSync. In this situation, LLBLGen Pro won't perform a fetch action to obtain the new entity values from the database.

To use this feature, you've to set the static/Shared property EntityBase.MarkSavedEntitiesAsFetched to true (default is false). This will be used for all entities in your application, so if you have some entities which have to be fetched after the update (for example because they have a timestamp field), you should keep the default, false. You can also set this value using the config file of your application by adding the following line to the appSettings section of your application's config file:

<add key="markSavedEntitiesAsFetched" value="true"/>

If you want to make sure refetches are done upfront. Then you should fetch the entities again into a new collection. i.e. - if you were updating an existing collection, use the same means (filters) you did to load it the first time, to reload it again. - If you were inserting new entities, then you can collect the PK values of the inserted entities, and use them as a range predicate to fetch the entities.

llblstc
User
Posts: 19
Joined: 06-Jul-2009
# Posted on: 12-Jan-2011 16:07:57   

I want the same instances to be refreshed (they are referenced from elsewhere) so something like

col.Refresh();

can this be done?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2011 16:46:27   

The entities will be refetched automaically when accessed.

There is no refresh or refetch on the collection. But there is a refetch on th entity.

llblstc
User
Posts: 19
Joined: 06-Jul-2009
# Posted on: 12-Jan-2011 16:49:28   

The entities will be refetched automaically when accessed.

I know, but i wanted to refresh them all in 1 sql and/or in on one connection.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 12-Jan-2011 17:48:37   

This isn't built in. You can use a Context object to fetch all entities in a collection again, and by using the Context you can fetch them into the same entity objects.

A refetch isn't required though. You can also mark saved entities as fetched automatically, this is a setting on EntityBase

Frans Bouma | Lead developer LLBLGen Pro