Setting the value of a related entity.

Posts   
 
    
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 16-Sep-2009 15:49:06   

Hi,

I'm having some issues related to the setting of a property of a related entity.

When I do the folowing:


        Dim obj As New Ec001Entity("UNiQUEiD")

        Using adapter As New DataAccessAdapter
            adapter.FetchEntity(obj)
            adapter.FetchEntityCollection(obj.Ec002, obj.GetRelationInfoEc002)
        End Using

        MsgBox(obj.Ec002(0).Ordnr)
        obj.Ec002(0).Ordnr = "ABC123"
        MsgBox(obj.Ec002(0).Ordnr)

The messagebox return 2 times "UNiQUEiD".

When I do:


        Dim obj As New Ec001Entity("UNiQUEiD")

        Using adapter As New DataAccessAdapter
            adapter.FetchEntity(obj)
            adapter.FetchEntityCollection(obj.Ec002, obj.GetRelationInfoEc002)
        End Using

        MsgBox(obj.Ec002(0).Ordnr)
        obj.Ec002(0).Fields("Ordnr").CurrentValue = "ABC123"
        MsgBox(obj.Ec002(0).Ordnr)

It returns the first messagebox box with "UNiQUEiD" and the second with "ABC123".

What is the difference between these 2 functionalities.

Thanks in advance

MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 16-Sep-2009 16:22:56   

Noticed the problem was in the Field I wanted to set. This is the key used to related from EC002 to EC001 and this prevented it to be set. If I call another property for example obj.Ec002(0).Groep = "15" that works perfectly

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Sep-2009 16:23:23   

Please check the following:

MsgBox(obj.Ec002.Count)
obj.Ec002(0).Ordnr = "ABC123"
MsgBox(obj.Ec002.Count)
MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 16-Sep-2009 16:42:54   

Eeek! Why is that? the first messagebox returns 45 the second 44.

Does this mean:

The EC002 collection still applies the relation with EC001 (Ordnr).

And when I edit the Ordnr of an entity in the EC002 collection that entity is lost because it doesn't apply to the relation with EC001 anymore.

So the collection is constantly updated?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Sep-2009 16:55:48   

Exactly, the entity got removed from the collection, because it was derefrenced from the main entity. No more related to the main entity.

But your second piece of code is basicly a hack, in which you avoid this logic.

MichielAlders avatar
Posts: 30
Joined: 01-Sep-2009
# Posted on: 16-Sep-2009 17:32:56   

I seriously underestimated the power of LLBLGEN Pro. That's very nice, didn't expect the collection to update itself.