entity and collection reference problem

Posts   
 
    
Tariq
User
Posts: 2
Joined: 02-Sep-2005
# Posted on: 13-Sep-2006 08:06:05   

Hi,

I've been using LLBL for a while now and i've noticed a very weird (possible bug) with the way referencing and derefrencing happens.

Typical scenario of an order and order items.

I first load an item:


Dim oItem as new ItemEntity(1)

I have a sub that all it does is load the order items in a member variable:


private sub foobar(byval poOrder as OrderEntity) 
  Dim oPred As New PredicateExpression
oPred.AddWithAnd(PredicateFactory.CompareValue(ItemFieldIndex.IsCurrent, ComparisonOperator.Equal, True))
oPred.AddWithAnd(PredicateFactory.CompareValue(ItemFieldIndex.Deleted, ComparisonOperator.Equal, False))
m_cOrderItems = oOrder.GetMultiItem(True, oPred)  

end sub

I then pass the related order to foobar to do some processing:


 foobar(oItem.Order) 

guess what order oItem now references ? ... nothing ! it is derefrenced !

fair enough if it was moved to another collection maybe , or maybe if it was byref , but it wasnt. Also the scope is different.

id like to know what the rules are for when an object is derefrenced from another and why? am i missing something major in my logic ?

is it a bug ?

Thanks in advance, Tariq

(PS. is there a document specifying the internal rules such as these- that ofcourse if its nto a bug )

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Sep-2006 08:22:47   

Is this real code that you have posted?

Coz you are not using the poOrder passed as a parameter to the foobar, instead you are using oOrder in your fetch (without the p)

If that's not the case, try to use ByRef for the parameter declaration.

Tariq
User
Posts: 2
Joined: 02-Sep-2005
# Posted on: 14-Sep-2006 01:58:10   

Walaa wrote:

Is this real code that you have posted?

Coz you are not using the poOrder passed as a parameter to the foobar, instead you are using oOrder in your fetch (without the p)

If that's not the case, try to use ByRef for the parameter declaration.

Hi Walaa,

Sorry you are right, i have rewritten the code to remove the part from a massive amount of code. It should be poOrder.

And it was originally byref but i changed it to byval as i thought that was the problem.

So any ideas ?

Thanks again, Tariq

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Sep-2006 08:26:10   

And what's the GetMultiItem [in "m_cOrderItems = oOrder.GetMultiItem(True, oPred)"] doing? would you please post the code of GetMultiItem ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 14-Sep-2006 18:02:59   

GetMultiItem is I think the generated method which returns Items (mapped on the relation with Item)

what does: "guess what order oItem now references ? ... nothing ! it is derefrenced !" mean? the variable oItem is nothing/null ? Right after you called Foobar?

It makes sense, as the items of the order are RELOADED, i.e in NEW instances.

You specify true, so you want the collection to be refetched. If you want the SAME instances, use a Context.

Frans Bouma | Lead developer LLBLGen Pro