Prefetch Path Question

Posts   
 
    
Posts: 3
Joined: 10-Mar-2010
# Posted on: 16-Mar-2010 20:11:09   

I am trying to do a join between two tables and return the results all at once. I am using SelfServicing:

            DealershipBoughtElsewhereCollection bews = new DealershipBoughtElsewhereCollection();
            IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.DealershipBoughtElsewhereEntity);
            prefetchPath.Add(DealershipBoughtElsewhereEntity.PrefetchPathDealership, 1, null, null, null);
            bews.GetMulti(null, prefetchPath);

When I use SQL Server profiler, I only see the "Select * from DealershipBoughtElseWhere". Why am I not seeing the inner join?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Mar-2010 21:25:52   

Because Prefetch paths are not Joins simple_smile

Prefetch paths are used to retrieve an entity and it's related entities - often called a "graph".

In your example below, you are retrieving all of the DealershipBoughtElsewhereEntitys, each with it's related Dealership entity. You should see 2 seperate sql queries, one for each table. LLBLGen then uses the results of each query to build the object graph for you.

SQL joins are known as Relations in the LLBLGen world, and are used to bring extra tables into the query - for example if you wanted to retrieve all DealershipBoughtElsewhereEntitys based on the name of a Salesman (Guessing at you entity structure here )

Getting you head round the difference between Prefetch paths and Relations is one of the largest initial stumbling blocks when using LLBLGen - we answer this question quite a lot simple_smile

Posts: 3
Joined: 10-Mar-2010
# Posted on: 17-Mar-2010 12:31:12   

So . . . then I beg the question, how could I use LLBLGen to return a "DataTable" or a a result set that would be equivalent to select * from a inner join b on a.id = b.fkid where {some clause goes here}

(Essentially for binding to a DataGrid or some other .Net Control?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Mar-2010 13:35:21   

You could investigate the use of TypedLists, TypedViews or DynamicLists, all of which allow the creation of joined, "flattened" queries.

Having said that, grids will bind to a hierarchical entity graph as well as a flattened view of the graph, which can be more useful in some scenarios (editable grids for example)

Matt