prefetching multiple associations at the same level

Posts   
 
    
kwo
User
Posts: 26
Joined: 29-Jul-2008
# Posted on: 29-Jul-2008 19:05:05   

I'm attempting to using linq to retrieve a populated object graph. It appears I'm not able to fetch multiple branches from the root. I've tried both approach 1 "WithPath and PathEdges" and approach 2 "WithPath and Lambda expressions".

This is the syntax I used for both approaches. The results I see in both cases is the the first association is not populated (i.e. VMBoxes). There are no errors, the association in the entity is just null. If I reverse the WithPath statements it is still the first association not populated (i.e. Agent). Am I using the correct syntax or is this not supported?

Approach 1:


var query = (from user in metadata.Users
                             select user)
    .WithPath(new PathEdge<VMBoxesEntity>(
        UsersEntity.PrefetchPathVmboxes,
        new PathEdge<VMMessagesEntity>(VMBoxesEntity.PrefetchPathVmmessages)))
    .WithPath(new PathEdge<AgentEntity>(
        UsersEntity.PrefetchPathAgent,
        new PathEdge<AgentSkillsEntity>(AgentEntity.PrefetchPathAgentSkills))));

Approach 2:


var query = (from user in metadata.Users
                             select user)
    .WithPath(vmBoxes => vmBoxes.Prefetch<VMBoxesEntity>(user => user.Vmboxes)
        .SubPath(vmMessages => vmMessages.Prefetch<VMMessagesEntity>(vmb => vmb.Vmmessages)));
     .WithPath(agent => agent.Prefetch<AgentEntity>(user => user.Agent)
         .SubPath(agentSkills => agentSkills.Prefetch<AgentSkillsEntity>(a => a.AgentSkills))

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jul-2008 04:58:00   

Hi kwo, your code is very close, however I think the it should look like this:

Using PathEdges

var query =
    (from user in metadata.Users
     select user)
        .WithPath(
            new PathEdge<VMBoxesEntity>(UsersEntity.PrefetchPathVmboxes,
                new PathEdge<VMMessagesEntity>(VMBoxesEntity.PrefetchPathVmmessages)),

            new PathEdge<AgentEntity>(UsersEntity.PrefetchPathAgent,
                new PathEdge<AgentSkillsEntity>(AgentEntity.PrefetchPathAgentSkills)));

Using Lambda expressions

var query = 
    (from user in metadata.Users
    select user)
    .WithPath(userPath => userPath
        .Prefetch<VMBoxesEntity>(user => user.Vmboxes)
            .SubPath(vmboxPath => vmboxPath.Prefetch<VMMessagesEntity>(vmb => vmb.Vmmessages))

        .Prefetch<AgentEntity>(user => user.Agent)
            .SubPath(agentPath => agentPath.Prefetch<AgentSkillsEntity>(a => a.AgentSkills)) );

You should use only one WithPath clause, the expression is a tree.

Let us know if you need further help wink

David Elizondo | LLBLGen Support Team
kwo
User
Posts: 26
Joined: 29-Jul-2008
# Posted on: 30-Jul-2008 23:07:47   

Worked like a champ. Thanks for the help.