Many-To-Many Prefetch Issue

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 05-Nov-2008 21:32:29   

LLBLGen Pro. Version: 2.6 Final (October 6th, 2008 ) Runtime Issue

This is my table structure TableA --- 1:n --- TableB ---- n:1 ---- TableC

I am trying to take advantage of the m:n relationships that llblgen detects.

When I use this prefetch path, I get all my related entites in Table C


IPrefetchPath2 pathA = new PrefetchPath2(EntityType.TableAEntity);
IPrefetchPathElement2 pathB = path.Add(TableAEntity.PrefetchPathTableB);
IPrefetchPathElement2 pathC = pathB.SubPath.Add(TableBEntity.PrefetchPathTableC);

When I use this prefetch path, I only get the first related entity in Table C


IPrefetchPath2 pathA = new PrefetchPath2(EntityType.TableAEntity);
IPrefetchPathElement2 pathC = path.Add(TableAEntity.PrefetchPathTableCViaTableB);

Why does using the m:n relationship only give me one result?

Edit: I am doing some more testing, it appears that this is an issue from calling IQueryable.First. When you call First (or Take(1)) it will be applied to the main query, as well as all the subqueries. Is this is expected behavior?


var q = from a in metaData.TableA
            select a;
q = q.WithPath(pathA);

q.First(); //returns first A entity, as well as first C entity

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Nov-2008 07:09:57   

Reproduced.

RTL 2.6.8.1013

Code

using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    // the query. Take 1 with a M:N path (Products via OrderDetails
    LinqMetaData metaData = new LinqMetaData(adapter);
    var q = (from o in metaData.Order
             select o).Take(1).WithPath(
                p => p.Prefetch(c => c.Products));

    // get the entity
    OrderEntity order = q.ToList()[0];

    // test 
    Assert.IsEqual(order.Products.Count == 3, "This order should have 3 products via order details");
}

We will look into it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 06-Nov-2008 11:35:01   

Bug in prefetch path m:n merger routine which produces a pk-pk fetch to tie the two sides together: it emits a limit into that query as well, which isn't necessary.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 06-Nov-2008 11:55:15   

Fixed in next build.

please see attached dll for the fix.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 112
Joined: 09-Aug-2004
# Posted on: 06-Nov-2008 15:12:11   

Thanks!