Answered by:
Retrieving all the data from an entity

Question
-
Hi,
I'm trying to get all the data from an entity, say in lots of 5000 records at a time. I'm trying to do something like this in code (as a recursive method)...
private int LoadData(string entityName, int pageNumber)
{
QueryExpression expression = new QueryExpression()
{
EntityName = entityName,
PageInfo = new PagingInfo()
{
PageNumber = pageNumber,
Count = 1,
ReturnTotalRecordCount = true
}
};
var entityCollection = connection.Connection.RetrieveMultiple(expression);
totalRecordCount += entityCollection.TotalRecordCount;
if (entityCollection.TotalRecordCountLimitExceeded)
{
LoadData(entityName, ++pageNumber);
}
return totalRecordCount;
}thinking that when it gets to the last page, the TotalRecordCountLimitExceeded property will be false but i dont think this is the case.
Any help appreciated
thanks,
Paul
Wednesday, November 21, 2012 12:38 PM
Answers
-
You should just be able to check the MoreRecords boolean on the results. From the sdk - http://msdn.microsoft.com/en-us/library/gg327917.aspx
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
CRM 2011 JavaScript Model Generator - CRM 2011 Appender for log4net- Edited by Blake ScarlavaiMVP Wednesday, November 21, 2012 1:44 PM link
- Proposed as answer by Blake ScarlavaiMVP Wednesday, November 21, 2012 3:04 PM
- Marked as answer by JLattimerMVP, Moderator Thursday, December 6, 2012 4:22 AM
Wednesday, November 21, 2012 1:43 PM
All replies
-
You should just be able to check the MoreRecords boolean on the results. From the sdk - http://msdn.microsoft.com/en-us/library/gg327917.aspx
Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
CRM 2011 JavaScript Model Generator - CRM 2011 Appender for log4net- Edited by Blake ScarlavaiMVP Wednesday, November 21, 2012 1:44 PM link
- Proposed as answer by Blake ScarlavaiMVP Wednesday, November 21, 2012 3:04 PM
- Marked as answer by JLattimerMVP, Moderator Thursday, December 6, 2012 4:22 AM
Wednesday, November 21, 2012 1:43 PM -
Please check following link
http://hachecrm2011.wordpress.com/2012/11/08/crm2011-and-c-avoiding-the-5000-records-limitation-paging-retrieve-multiple-results/I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Mubasher Sharif
Check out my about.me profile!
http://mubashersharif.blogspot.com
Linked-In Profile
Follow me on Twitter!Wednesday, November 21, 2012 1:48 PM