Problem getting User from User Profile
I have a function where I have to search profiles in the system based on last name. When looking at the API docs here: docs.sitefinity.com/.../for-developers-user-profiles (note I am using 7.3) I see that User is a property of the Sitefinity Profile, yet I can't seem to reference it here:
public static List<SupervisorListResponse> GetUsersByName(string input)
var result = new List<SupervisorListResponse>();
try
var manager = UserProfileManager.GetManager();
var profiles = manager.GetUserProfiles()
.OfType<SitefinityProfile>().Where(p => p.LastName.Contains(input));
if (profiles.Any())
result = profiles.Select(
u => new SupervisorListResponse
UserId = u.User.Id,
EmailAddress = u.User.Email,
LastName = u.LastName,
FirstName = u.FirstName
).ToList();
catch (Exception ex)
ErrorSignal.FromCurrentContext().Raise(ex);
Log.Error("Error retreiving users with criteria " + input, ex);
return result;
SupervisorResponse is a simple class - I can provide it if needed.
Now I am capturing the error in Elmah, and that's what has me very confused. The error states:
Telerik.OpenAccess.OpenAccessException: Field 'User' not found on class 'Telerik.Sitefinity.Security.Model.SitefinityProfile'.
at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type resultType, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) --- End of inner exception stack trace ---
at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) at Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQueryMulti[T](Expression expr, ExecutionSettings settings, Object[] grpVals, Boolean checkOid, QueryOptions options) at Telerik.OpenAccess.Query.Piece`1.ExecuteMultiple() at Telerik.Sitefinity.Data.Linq.LinqQuery`2.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
And the code up top may not be matching to this error now, I rolled things back to try to get back to the original after a few hours of manipulating. Any thoughts?
Hi George,
What I can suggest is to call ToList() to the profiles collection:
var profiles = manager.GetUserProfiles()
.OfType<SitefinityProfile>().Where(p => p.LastName.Contains(
input
)).ToList();