views:

24

answers:

1

I have 3 objects in my model thus:
Customer 1-----* Region 1-----* Branch

To get the Customer from the Branch in code seems simple enough: branch.Region.Customer
I would need to get all of the Branches belonging to a given Customer though and suspect that customer.Regions.Branches would not work due to customer.Regions being a collection.

Having Customer link directly to Branch would be redundant for me as the region already contains the customer information (each customer has different region boundaries so there is no mileage in separating the Regions out here.)

I know that in ActiveRecord as used in Ruby on Rails this would be possible using "has_many_through" but can it be done in the ADO.NET Entity Framework? If so how?

Thanks a lot for reading all of this.

+1  A: 

There is nothing built in. I would probably work around this with a query:

public static IQueryable<Branch> CustomerBranches(
    MyObjectContext context, Guid customerId)
{
    return from c in context.Customers
           where c.Id == customerId
           from r in c.Regions
           from b in r.Branches
           select b;
}
Craig Stuntz
That's how I went about it thanks, shame there's nothing built in for that.
ridecar2