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.