Improvement suggestion for performance

Aug 2, 2011 at 7:04 PM

Instead of using a loop to go against profile manager, it is very much faster to use a query, dumping the results into the grid. Profile manager is a very slow process. Here is a code snippet that is part of how we did this (sorry about the formatting):

{

 using (SPSite site = new SPSite(SPContext.Current.Site.ID))

 

{

 var query = new FullTextSqlQuery(site)

{

 

QueryText =

string.Format("SELECT PreferredName, JobTitle, Other, WorkPhone, StreetAddress, City, state, PictureURL, postalCode, WorkEmail, AccountName FROM Scope() WHERE CONTAINS ('\"{0}\"') AND \"Scope\"='People' ORDER BY PreferredName",this.HRDepartment),

ResultTypes =

ResultType.RelevantResults,

RowLimit=1000

 var queryResults = query.Execute();

 var queryResultsTable = queryResults[ResultType.RelevantResults];

 var results = new DataTable();

dt.Load(queryResultsTable,

LoadOption.OverwriteChanges);

v.Sort ="PreferredName ASC";

dt = v.ToTable();

 return dt;

 }

});

 DataView v = dt.DefaultView;

 };