Linq to EntityCollection with prefetches

Posts   
 
    
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 21-Apr-2011 17:53:58   

Hello Can someone please help me as to why this statement is not returning my prefetches

Thanks

result.WithPath(x => x .Prefetch<AccountEntity>(a => a.AccountUsingAccountIdToAccountId) .Prefetch<TicketTypeEntity>(tt => tt.TicketTypeUsingTicketTypeIdToTicketTypeId) .Prefetch<TicketPriorityEntity>(tp => tp.TicketPriorityUsingTicketPriorityIdToTicketPriorityId) .Prefetch<StatusEntity>(s => s.StatusUsingStatusIdToStatusId) );

            return ((ILLBLGenProQuery) result).Execute<EntityCollection<TicketEntity>>();
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Apr-2011 21:28:29   

Assuming that "result" looks something like

from t in metaData.Ticket
         where t.TicketId == 1234
         select t

please could you try something like


(from t in metaData.Ticket
         where t.TicketId == 1234
         select t)
.WithPath(x => x
                                         .Prefetch<AccountEntity>(t => t.AccountUsingAccountIdToAccountId)
                                         .Prefetch<TicketTypeEntity>(t => t.TicketTypeUsingTicketTypeIdToTicketTypeId)
                                         .Prefetch<TicketPriorityEntity>(t => t.TicketPriorityUsingTicketPriorityIdToTicketPriorityId)
                                         .Prefetch<StatusEntity>(t => t.StatusUsingStatusIdToStatusId)
                    );


Note that all of the pre-fetch paths now reference the "t" from the original query.

Let us know if this is any more successful.

Thanks

Matt

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Apr-2011 06:37:51   

Added to Matt's post:

  • Make sure you are using the latest runtime library version.
  • Added to above requirement, always post your used runtime library version. In general, read this: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12769
  • What is "result" variable stands for? Please paste all the relevant code.
  • Review the Generated SQL. That could make us hints of what is going on.
  • When you say that "it's not returning the expected prefetches" please make sure the data you are testing is actually meant for return prefetches.
David Elizondo | LLBLGen Support Team
Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 22-Apr-2011 10:10:23   

My apologies for not giving enough data.

I am using version 3.0.10.0927

This is the generated sql ADO.NET:Execute Reader "SELECT TOP 25 [LPA_L1].[AccountId], [LPA_L1].[AssignedToUserId], [LPA_L1].[Created], [LPA_L1].[DepartmentId], [LPA_L1].[Description], [LPA_L1].[isActive] AS [IsActive], [LPA_L1].[isStaffResponse] AS [IsStaffResponse], [LPA_L1].[LastModified], [LPA_L1].[LastModifiedUserId], [LPA_L1].[LinkKey], [LPA_L1].[Metric], [LPA_L1].[Name], [LPA_L1].[OldTicketId], [LPA_L1].[OldTicketRating], [LPA_L1].[Reference], [LPA_L1].[StatusId], [LPA_L1].[TicketId], [LPA_L1].[TicketPriorityId], [LPA_L1].[TicketRatingId], [LPA_L1].[TicketTypeId] FROM [AxxessRad].[dbo].[Ticket] [LPA_L1] WHERE ( ( ( ( ( ( ( [LPA_L1].[StatusId] = @p1)) AND ( [LPA_L1].[AssignedToUserId] IS NOT NULL)))))) ORDER BY [LPA_L1].[Created] ASC" The command text "SELECT TOP 25 [LPA_L1].[AccountId], [LPA_L1].[AssignedToUserId], [LPA_L1].[Created], [LPA_L1].[DepartmentId], [LPA_L1].[Description], [LPA_L1].[isActive] AS [IsActive], [LPA_L1].[isStaffResponse] AS [IsStaffResponse], [LPA_L1].[LastModified], [LPA_L1].[LastModifiedUserId], [LPA_L1].[LinkKey], [LPA_L1].[Metric], [LPA_L1].[Name], [LPA_L1].[OldTicketId], [LPA_L1].[OldTicketRating], [LPA_L1].[Reference], [LPA_L1].[StatusId], [LPA_L1].[TicketId], [LPA_L1].[TicketPriorityId], [LPA_L1].[TicketRatingId], [LPA_L1].[TicketTypeId] FROM [AxxessRad].[dbo].[Ticket] [LPA_L1] WHERE ( ( ( ( ( ( ( [LPA_L1].[StatusId] = @p1)) AND ( [LPA_L1].[AssignedToUserId] IS NOT NULL)))))) ORDER BY [LPA_L1].[Created] ASC" was executed

This is the linq (excluding the where)

var accountId = from account in metaData.Account where account.PastelAccountNumber == PastelAccNo select new {account.AccountId};

            var query = from ticket in metaData.Ticket
                        select ticket;

            var result = query;         

            result = result.OrderBy(x => x.Created).TakePage(PageNumber, PageSize);

            result.WithPath(x=>x
                .Prefetch<AccountEntity>(ticket => ticket.AccountUsingAccountIdToAccountId)
                                     //.Prefetch<TicketTypeEntity>(tt => tt.TicketTypeUsingTicketTypeIdToTicketTypeId)
                                     //.Prefetch<TicketPriorityEntity>(tp => tp.TicketPriorityUsingTicketPriorityIdToTicketPriorityId)
                                     //.Prefetch<StatusEntity>(s => s.StatusUsingStatusIdToStatusId)
                );

            return ((ILLBLGenProQuery) result).Execute<EntityCollection<TicketEntity>>();

Please tell me if more data is required

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Apr-2011 13:16:24   

Similar to OrderBy, WithPath returns a new IQueryable. So you should assign it to a variable and that's the one you enumerate.

e.g result = result.WithPath()...

Jed
User
Posts: 38
Joined: 08-Oct-2010
# Posted on: 22-Apr-2011 16:02:17   

Wow what a silly mistake my apologies. Thank You