Fetching an entitycollection with already existing data

Posts   
 
    
mfas
User
Posts: 6
Joined: 27-Jun-2006
# Posted on: 26-Oct-2006 14:13:57   

Hi,

I have an entitycollection which can be altered multiple places in an mdi windows application. While this works flawlessly in most cases, I can not figure out how to fetch entities into a given collection while not fetching the entities already present.

I have the following table hierarchy:

Case -> Case2Item -> Item Case -> Case2TurbineUnitType -> Case2TurbineUnitType2Case2Item -> Case2Item -> Item

In my application this means I have multiple ways of manipulating the Case2Item table. What I need is, that when I have fetched the relevant Case2Item entries in one window, I would like to fetch the remaining Case2Item entries via another fetch in another window. I actually need to do this in a prefetchpath and have tried the following:

  Using daa As New DataAccessAdapter(True)
    Dim filterBucket As IRelationPredicateBucket = New RelationPredicateBucket()
    filterBucket.PredicateExpression.AddWithAnd(Case2TurbineUnitTypeFields.CaseId = CaseId)
    Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(EntityType.Case2TurbineUnitTypeEntity)
    Dim ppe As IPrefetchPathElement2 = prefetchPath.Add(Case2TurbineUnitTypeEntity.PrefetchPathCase2TurbineUnitType2Case2Item)
    Dim ppf As IPredicateExpression = New PredicateExpression()
    For Each entity As Case2ItemEntity In oCase.Case2Item
      ppf.AddWithAnd(Case2ItemFields.Case2ItemId <> entity.Case2ItemId)
    Next
    ppe.SubPath.Add(Case2TurbineUnitType2Case2ItemEntity.PrefetchPathCase2Item, 0, ppf).SubPath.Add(Case2ItemEntity.PrefetchPathItem).SubPath.Add(ItemEntity.PrefetchPathERPSystem)
    daa.FetchEntityCollection(ecSave, filterBucket, prefetchPath)
    daa.CloseConnection()
  End Using

However this does not seem to work as I get duplicate entries from the Case2Item table in my subsequent object model. How do I solve this?

I am using LLBL 2.0.0.0 October 3rd edition, SQL Server 2000 database, Adapter template.

I am looking forward to hearing from you.

Regards, Michael Fastrup

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Oct-2006 15:39:10   

So you have Case2Item table, from which you have loaded some entities in one form. Now in another form you want to load the all the Case2Item entities in the database except those previously loaded in the first form.

If I understand you correctly, then all you need in the second form is to filter entities to be fetched, to filter out those with PKs fetched in the first entity. For this you may use FieldCompareRangePredicate with the negate property set to true.

Please refer to the LLBLGen Pro manual for FieldCompareRangePredicate.

mfas
User
Posts: 6
Joined: 27-Jun-2006
# Posted on: 27-Oct-2006 07:29:07   

Thanks a bunch - that was spot on. Just could not see the forest for all the trees :-)