Refetch or refresh child collections

Posts   
 
    
Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 03-Aug-2007 10:21:08   

Hi,

I'm creating a master-detail form where the user will be able to edit the master-entity, as well as a child-collection (much like an order/order-detail-form), using LLBLGenPro v2.0.0.0 Final (July 6th, 2007), runtime library version 2.0.7.605.

However, when the save fails because, for instance, a new detail-row has some invalid data, I want to cancel the changes and show the old entity and childcollections.

This works for the entity, but the child collections don't get refreshed => the invalid order-detail row is still showing.

Is there a way to make sure all child-collections get refreshed? (or is this something that should work when calling MasterEntity.Refetch() and is there some simple step i'm missing?)

Is there a way to refresh just the child collection?

greets,

Peter

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2007 11:49:22   

Could you post the refresh routine you are using? and What Generator Template Set are you using (Adapter or Selfservicing)?

David Elizondo | LLBLGen Support Team
Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 03-Aug-2007 14:31:18   

I use the Self-Servicing template group for SqlServer.

All controls are bound to a bindingsource, with an entitycollection as datasource.

In code I get a reference to the current item using this bindingsource's currencymanager:

cmOverview = mainBindingSource.CurrencyManager;
m_Entity = (EntityBase)cmOverview.Current;
m_Entity.Save(true);

If the save fails I try to refetch the entity using:

m_Entity.Refetch();

This works for the entity, but it seems like the child collections don't get refetched.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Aug-2007 16:31:19   

Refetch() only fetches the entity on which Refetch was called. You should re-fetch (fetch again) the entire graph. (Main entity and childres probably using a PreftechPath). The same you did when you first loaded the form.

Here is a previous discussion about the same subject: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10537

Piedro
User
Posts: 24
Joined: 17-Jan-2007
# Posted on: 07-Aug-2007 12:28:20   

The same you did when you first loaded the form.

The thing is that I didn't do anything to get the child collections. I use databinding and rely on the databinding mechanism to get the child-collections for me. And it works fine. simple_smile

The only problem is refetching the entity-graph in case of a cancel.

I can loop through the child-collections: (this snippet checks which childcollections have changes and uses the local variable m_Entity of type EntityBase)


List<IEntityCollection> childCollections = m_Entity.GetMemberEntityCollections();
for (int i = 0; i < childCollections.Count; i++)
            {
                IEntityCollection col = childCollections[i];
                if (col != null && col.ContainsDirtyContents)
                {
                    if (!m_IsDirty) m_IsDirty = true;
                    m_UnitOfWork.AddCollectionForSave(col);
                }
            }

I could use a similar approach to refetch the collection, but I don't see an appropriate method to do this. If I use GetMulti(null), I get all order-details and not just the details related to this order.

So, is there a way to refresh a collection taking into account the relation with it's parent entity? (Without manually creating a filter, I mean)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 08-Aug-2007 15:13:02   

You mean, effectively execute lazy loading ? You can, by specifying forceFetch = true with the child.GetMulti<parentEntity>() routine

Frans Bouma | Lead developer LLBLGen Pro