Recursive Save when Manually setting EntityRelations

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 12-Apr-2007 20:46:48   

I have 2 tables (customers,orders) that I have manually created EntityRelations/PrefetchPaths for successfully. (Can't be done in the designer as there is no real PK defined, the tables use composite keys but are logically joined by customer.CustID=order.CustID)

I got this to work in getting the heiracrchy after adding the required plumbing.

IPrefetchPath prefetch = new PrefetchPath((int)EntityType.CustomerEntity);
prefetch.Add(CustomerEntity.PrefetchPathOrderCollection);
CustomerEntity c= new CustomerEntity (27, prefetch);

c.Orders = all the orders for the customers.

Now what do I have to do so that I can change/add/delete items in the c.Orders collection and have them all save with the right PK/FK when I call this.

c.Save(true);

I assume there is some plumbing where I have to tell the CustomerEntity that it has Orders and that there is a PK/FK relationship and what that relationship is etc. probably related to CustomerEntity.GetDependentRelatedEntities() and CustomerEntity.GetMemberEntityCollections() ?? I didn't see anything in the manual related to them though. LLBL of course generates these functions with no entities as there are no relationships in the designer.

Thanks, Ian

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Apr-2007 13:10:28   

I think GetMemberEntityCollections is the one to use. The following is copied from the reference manual:

Gets a list of all entity collections stored as member variables in this entity. The contents of the list is used by the Save logic to perform recursive saves. Only 1:n related collections are returned.

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 13-Apr-2007 13:16:03   

The CustomerEntity.cs class file has this generated (SelfServicing)

public override List<IEntityCollection> GetMemberEntityCollections()
{
            List<IEntityCollection> toReturn = new List<IEntityCollection>();
            return toReturn;
}

I create a partial class CustomerEntity.partial.cs

in that I would then need to replace the GetMemberEntityCollections() but because it's public override already, I can't.

Is there a way to replace GetMemberEntityCollections() in CustomerEntity.cs with my own in CustomerEntity.partial.cs?

Thanks for all your help.

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 13-Apr-2007 14:10:41   

I think I have an answer. Using the TwoClasses generation option for Self-servicing appears to let me override the GetMemberEntityCollections() method.

Ian

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Apr-2007 16:36:18   

Glad you have found a solution to your issue.