Very simple question..I guess...

Posts   
 
    
llblPowa
User
Posts: 41
Joined: 19-Nov-2006
# Posted on: 08-Feb-2007 16:04:16   

Hello,

Can anybody tell me why the following does not work and how I can do it ?

car.wheel =carManager.FetchWheelCollection(carID);

Compilator told me that the Wheel collection is read only.

Once I have retrieved the wheels of a car, how can I create the link between the car and its wheels (I do not want to use prefetch patch)?

It is a 1:n relation. A car can have 4 wheels. a wheel belongs to only 1 car.

Cheers,

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 08-Feb-2007 16:31:56   

Hello,

entity collections links are read only. So you have to link each entity of your entity collection to your entity. Example :

for each myWheel as wheel in carManager.FetchWheelCollection(carID)) mywheel.car=car

And if you save car, it will save the car entity and all the wheel linked.

llblPowa
User
Posts: 41
Joined: 19-Nov-2006
# Posted on: 08-Feb-2007 16:56:41   

When I try your suggestion, I am having the following error:

Collection was modified; enumeration operation may not execute.
llblPowa
User
Posts: 41
Joined: 19-Nov-2006
# Posted on: 08-Feb-2007 16:59:57   

ok, with a for, it is working fine. However, don't you have any other options? It seems to me as a weird walkaround?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Feb-2007 08:35:23   

I'm not familier with the manager templates, but I think you may implement the following if you can't find it:


// fetch the orders of a certain product
ProductEntity product = new ProductEntity(10);
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntityCollection(product.Orders, product.GetRelationInfoOrders());