MaxAmountOfItemsToReturn Problem

Posts   
 
    
Posts: 98
Joined: 09-Feb-2005
# Posted on: 19-May-2006 00:20:08   

Hello, I'm struggling with limiting the number of results I am returning from a query. Below is the code:


            UserProfileEntity userProfile = new UserProfileEntity(upc.UserADNames[0]);

            PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.UserProfileEntity);
            IPrefetchPathElement2 sessionPath = UserProfileEntity.PrefetchPathSessionCollection;
            sessionPath.MaxAmountOfItemsToReturn = 1;
            sessionPath.Sorter.Add(SessionFields.SessionDate | SortOperator.Descending);
            prefetch.Add(sessionPath);
            prefetch.Add(UserProfileEntity.PrefetchPathSearchType);
            prefetch.Add(UserProfileEntity.PrefetchPathSearchCriteriaCollection);
            prefetch.Add(UserProfileEntity.PrefetchPathLanguage);
            prefetch.Add(UserProfileEntity.PrefetchPathLocation);
            
            //Adapter.FetchEntity
            Adapter.FetchEntity(userProfile, prefetch);

And here is a portion of the trace.

Method Exit: CreateSelectDQ Method Exit: CreatePagingSelectDQ: no paging. 'nunit-gui.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll', No symbols loaded. Method Enter: CreatePagingSelectDQ Method Enter: CreateSelectDQ Method Enter: CreateSelectDQ Generated Sql query: Query: SELECT [VC_to_Galaxy].[dbo].[tbl_UserProfile].[UserADName] AS [UserAdname], [VC_to_Galaxy].[dbo].[tbl_UserProfile].[CostCenterID] AS [CostCenterId], [VC_to_Galaxy].[dbo].[tbl_UserProfile].[LocationID] AS [LocationId], [VC_to_Galaxy].[dbo].[tbl_UserProfile].[LanguageID] AS [LanguageId], [VC_to_Galaxy].[dbo].[tbl_UserProfile].[SearchTypeID] AS [SearchTypeId] FROM [VC_to_Galaxy].[dbo].[tbl_UserProfile] WHERE ( ( [VC_to_Galaxy].[dbo].[tbl_UserProfile].[UserADName] = @UserAdname1)) Parameter: @UserAdname1 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: 29c24c0b-8f1d-4be4-9199-c18377a204a5.

Method Exit: CreateSelectDQ Method Exit: CreatePagingSelectDQ: no paging. Method Enter: CreatePagingSelectDQ Method Enter: CreateSelectDQ Method Enter: CreateSelectDQ Generated Sql query: Query: SELECT [VC_to_Galaxy].[dbo].[tbl_Session].[SessionID] AS [SessionId], [VC_to_Galaxy].[dbo].[tbl_Session].[UserADName] AS [UserAdname], [VC_to_Galaxy].[dbo].[tbl_Session].[SessionDate], [VC_to_Galaxy].[dbo].[tbl_Session].[SessionDuration] FROM [VC_to_Galaxy].[dbo].[tbl_Session] WHERE ( ( ( [VC_to_Galaxy].[dbo].[tbl_Session].[UserADName] = @UserAdname1))) ORDER BY [VC_to_Galaxy].[dbo].[tbl_Session].[SessionDate] DESC Parameter: @UserAdname1 : String. Length: 50. Precision: 0. Scale: 0. Direction: Input. Value: 29c24c0b-8f1d-4be4-9199-c18377a204a5.

I'm trying to only pull the latest Session object, but I'm getting all of them returned to me. I saw on a previous post that TOP can not be used with certain field types, but tbl_Session is only using int, datetime, decimal, and nvarchar.

Am I not using the prefetch appropriately for this?

Thanks all.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-May-2006 08:42:00   

First of all: do you get the results you want? Prefetch paths don't use TOP for limiting, as that wouldn't work: say I have 10 customers and I want 1 order for each of them using a prefetch path. I then can't do select top 1 * from orders. I have to limit on the client side. I also can't limit on TOP 10*1, because that still can bring entities back for just the first customer.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 09-Feb-2005
# Posted on: 19-May-2006 16:21:09   

Ah, right. I was only pulling a single entity and not even thinking of that. I'll just load it separately and add it to a collection. Thanks! I'll mark this one done