EntityCollection<T> EntityAdding

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 26-Jun-2008 20:50:29   

My goal is to set default values on the OrderEntity when ever a new one is made during databinding's AddNew() and added to it's collection.

Structure:

I have an EntityCollection<Customer> called "Customers" and each CustomerEntity has an EntityCollection<Order> "Orders" filled in via an Adapter from a Linq Query using the Execute() command.

How do I catch the event 'EntityAdding' on the orders collection so I can modify the OrderEntity before it goes into the Orders collection?

There is no Customer.Orders like in the SelfServicing model, so I'm not sure where to get it from.

I created an OrderCollection class, but am not sure how to get the adapter when it fills the Customers to use that instead of EntityCollection<OrderEntity>

    
public class Orders: EntityCollection<OrderEntity>
    {
        protected override bool OnEntityAdding(OrderEntityentityToAdd)
        {
            return base.OnEntityAdding(entityToAdd);
        }
    }

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 27-Jun-2008 11:55:29   

I created an OrderCollection class, but am not sure how to get the adapter when it fills the Customers to use that instead of EntityCollection<OrderEntity>

You'll need to fetch the customer alone, then fetch the related Orders collection.

CustomerEntity customer = new CustomerEntity("CHOPS");
DataAccessAdapter adapter = new DataAccessAdapter();
EntityCollection<OrderEntity> orders = customer.Orders;
adapter.FetchEntityCollection(orders, customer.GetRelationInfoOrders());

You may derive from the OrderEntity, and use the derived class in your orders entityCollection definition.