1:m across a 1:1 relationship

Posts   
 
    
Darwin avatar
Darwin
User
Posts: 38
Joined: 12-Apr-2005
# Posted on: 24-May-2005 00:43:55   

Employee is in a 1: 1 relationship with Contact. Phone is in a m:1 relationship with Contact. I need to get the Phone Numbers for an Employee.

In project explorer nothing related to Contact is automatically discovered from within the Employee. I cannot add the relationship manually. I would need to add a 1: m relationship for Employee - Phone, but using the Employee.ContactID as the key on the Employee side, not the Employee ID. Or I tried to add a m:n relationship manually. To do this the first side must be in a 1:n relationship... which Employee - Contact is not, so it can't be used.

How do I do this?

Thanks, Darwin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-May-2005 08:14:24   

Darwin wrote:

Employee is in a 1: 1 relationship with Contact. Phone is in a m:1 relationship with Contact. I need to get the Phone Numbers for an Employee.

In project explorer nothing related to Contact is automatically discovered from within the Employee. I cannot add the relationship manually. I would need to add a 1: m relationship for Employee - Phone, but using the Employee.ContactID as the key on the Employee side, not the Employee ID. Or I tried to add a m:n relationship manually. To do this the first side must be in a 1:n relationship... which Employee - Contact is not, so it can't be used.

You select phone entities based on a filter on employee. So:


RelationCollection relations = new RelationCollection();
relations.Add(PhoneEntity.Relations.ContactEntityUsingContactID);
relations.Add(ContactEntity.Relations.EmployeeEntityUsingContactID);
PredicateExpression filter = new PredicateExpression();
filter.Add(...// here you add the filter on employee);

Now, you pass relations and filter to a PhoneCollection.GetMulti() to get the phones.

Frans Bouma | Lead developer LLBLGen Pro