SaveEntity with recurse

Posts   
 
    
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 09-Jul-2005 20:03:04   

I've retrieved a [dispute] entity along with related entities using a prefetch path. One of the prefetched entities (Status) is related n-1 via statusid. If I change the statusid of [dispute] and adapter.SaveEntity( [Dispute], true, null, true) or adapter.SaveEntity( [Dispute], true)

Is there a way to refresh the prefetch path entities and collections after the save? Does specifying recurse do this? I don't think the entity remembers its prefetch path, right?

Is there a good way to tuck away the prefetch path originally used and have it reused following the save as part of the reread?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Jul-2005 10:05:22   

If you want to refetch a complete tree, in the same OBJECTS if possible, add the root to a Context instance, then save the entities, then simply refetch the root and pass in the prefetch path and the context. This then should refetch the entities in the same objects and eventually add new ones

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 11-Jul-2005 13:04:25   

Thanks, I've not worked with contexts yet. So this is better than just fetching the root object with the same prefetch path because it is reusing objects when possible? Any other benefits? As it is adding new entities, is it also getting rid of any that are no longer in the graph?

arschr
User
Posts: 893
Joined: 14-Dec-2003
# Posted on: 11-Jul-2005 13:07:30   

Is there a reason you don't have the root entity remember the prefetch path used to fetch it's children? I seem to remeber an issue with there being state kept in the prefetch path so that it has to be recreated with each use rather than using a saved version. Am I remembering correctly?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 11:45:56   

arschr wrote:

Thanks, I've not worked with contexts yet. So this is better than just fetching the root object with the same prefetch path because it is reusing objects when possible?

Yes, it will first fetch the data again, and then will re-use an existing entity object if that entity is already loaded before, instead of using a new one. This then makes it possible to fetch new nodes into the current graph, while keeping existing entity instances.

Any other benefits?

Not in this context (no pun wink ). Though all entities in the graph are available via the context as well, so you can for example get a hold of an entity directly through the Context object by specifying a type and the PK field(s) value(s).

As it is adding new entities, is it also getting rid of any that are no longer in the graph?

No.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Jul-2005 11:47:26   

arschr wrote:

Is there a reason you don't have the root entity remember the prefetch path used to fetch it's children? I seem to remeber an issue with there being state kept in the prefetch path so that it has to be recreated with each use rather than using a saved version. Am I remembering correctly?

State in the path was an issue, but isn't an issue anymore. You can safely re-use a prefetch path if you want.

The path isn't stored inside an entity, as it belongs (IMHO) to the action fetching the entity, so it doesn't belong to the entity being the root. Also, when you fetch a collection as root, where to store the path? In each entity in the collection or in the collection?

Frans Bouma | Lead developer LLBLGen Pro
mkamoski avatar
mkamoski
User
Posts: 116
Joined: 06-Dec-2005
# Posted on: 21-Jun-2006 15:42:19   

Otis wrote:

Also, when you fetch a collection as root, where to store the path? In each entity in the collection or in the collection?

Here is a thought.

Maybe one could add an overload to SaveEntity() such that it is possible to pass in a PrefetchPath.

In that way, if RefetchAfterSave=True and if PrefetchPath=NonNull, then the Refetch could use the Prefetch and voila.

The old overloads would still exist; so, the API would not break. The new overload would allow a little more flexibility for those who use it. This might help to cover some of the special cases.

And so on.

Just a thought.

Thank you.

--Mark Kamoski

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Jun-2006 16:44:27   

I need a clear example, I have no clue what's discussed, as I've mentioned also in that other thread. Please continue in that thread simple_smile

Frans Bouma | Lead developer LLBLGen Pro