Getting a related name

Posts   
 
    
Ceres
User
Posts: 20
Joined: 31-Jan-2007
# Posted on: 31-Jan-2007 17:32:08   

Hello,

I'm exploring LLBLGenPro by using V2, Adapter, VB and the Northwind db. I can see how to get all Orders by:

Dim allOrders AS New EntityCollection(Of OrdersEntity)(New OrdersEntityFactrory())
adapter.FetchEntityCollection(allOrders, Nothing)

..but how does one do a join to the Customer table to retrieve the related Customer name, so I can use it instead of the Customer ID confused .

Thanks for your response

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 01-Feb-2007 03:47:20   

You will want to define a prefetch path for your orders collection. This way you will retrieve all orders and all of the orders related customers. So something like this would work

EntityCollection orders = new EntityCollection(new OrderEntityFactory());
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.OrderEntity);
prefetchPath.Add(OrderEntity.PrefetchPathCustomer);
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntityCollection(orders, filter, prefetchPath);

Now each OrderEntity in the orders collection has their related CustomerEntity fetched to access the Customer.Name. So you could do

orders[0].Customer.Name;

This is explained a bit more in the PrefetchPath section of the manual.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Feb-2007 10:38:47   

If you want the related Companyname in the order, you can map a field on the related field 'CompanyName' in the order entity. Then use BClubb's code to fetch the data.

Frans Bouma | Lead developer LLBLGen Pro