Linq query - First() method also affecting prefetches

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 17-Dec-2008 04:22:09   

Hello,

I have this query:

var category = (from c in data.Category.WithPath(p => p.Prefetch<PictureEntity>(pc=>pc.PictureCollectionViaPictureCategory).Exclude(t => t.PictureData).FilterOn(t=>t.IsActive == true))
                            where c.Url == name
                            select c).First();

Which get the category as expected. What it doesn't do right i prefetch the PictureCollectionViaPictureCategory collection. It gets only the TOP 1

exec sp_executesql N'SELECT DISTINCT TOP 1 [LPA_C1].[CategoryId] AS [CategoryId0], [OnlyFunPics].[dbo].[Picture].[PictureId] AS [PictureId1] FROM (( [OnlyFunPics].[dbo].[Category] [LPA_C1]  INNER JOIN [OnlyFunPics].[dbo].[PictureCategory] [LPA_P2]  ON  [LPA_C1].[CategoryId]=[LPA_P2].[CategoryId]) INNER JOIN [OnlyFunPics].[dbo].[Picture]  ON  [OnlyFunPics].[dbo].[Picture].[PictureId]=[LPA_P2].[PictureId]) WHERE ( ( ( ( [LPA_P2].[CategoryId] = @CategoryId1)) AND ( [OnlyFunPics].[dbo].[Picture].[IsActive] = @IsActive2)))',N'@CategoryId1 int,@IsActive2 bit',@CategoryId1=1,@IsActive2=1

Seriously this has to be a bug. If I call First() then obviously I only want the first category, i don't want the First effect to cascade down to my prefetches...

This code works as I expected the original code to (i get a complete prefetch):

var categories = (from c in data.Category.WithPath(p => p.Prefetch<PictureEntity>(pc=>pc.PictureCollectionViaPictureCategory).Exclude(t => t.PictureData).FilterOn(t=>t.IsActive == true))
                            where c.Url == name
                            select c);

                var category = categories.ElementAt(0);

I don't know how to get my build version.. My SD.LLBLGen.Pro.ORMSupportClasses.NET20 dll is 'product version' 2.6.08.1013, my linq dll is 2.6.8.1001

I'll try updating to latest build... now where's my password... disappointed

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 17-Dec-2008 05:06:05   

Updated to 8th of december build and it's working now.