I have troubles with CRM2011:
All new users created in the Active Directory have bad performances when the code tries to retrieve data from the database via linq queries using the IOrganizationService. The new users have the same rights than the old users.
Here is some code for better understanding. Activity is an ActivityPointer, I try to get all the attachments linked to it: ( the slow part is when i try to use one of the items of the ActivityAttachments property)
foreach (var attachment in activity.ActivityAttachments)
{
//Do stuff
}
ActivityAttachments is the result of a linq query using the datacontext
public IEnumerable<ActivityMimeAttachment> ActivityAttachments
{
get { return Datacontext.ActivityMimeAttachmentSet.Where(a => a.ObjectId != null && a.ObjectId.Id == Id).Select(a => new ActivityMimeAttachment(a)); }
}
and the datacontext is my datamodel - created and stored for each user as my crmservice , instance of my organizationservice
private static readonly ConcurrentDictionary<string, LeDataModel> _dataModels = new ConcurrentDictionary<string, LeDataModel>();
protected LeDataModel Datacontext
{
get
{
LeDataModel _model;
if (HttpContext.Current != null)
{
var currentUser = HttpContext.Current.User.Identity.Name;
if (!_dataModels.TryGetValue(currentUser, out _model))
{
_model = new LeDataModel(CrmService) { MergeOption = MergeOption.NoTracking };
_dataModels.TryAdd(currentUser, _model);
}
}
else
{
_model = AdminDataContext;
}
return _model;
}
}
protected OrganizationService CrmService
{
get
{
OrganizationService _service;
if (HttpContext.Current != null)
{
var currentUser = HttpContext.Current.User.Identity.Name;
if (!_services.TryGetValue(currentUser, out _service))
{
_service = new OrganizationService("Crm");
_services.TryAdd(currentUser, _service);
}
}
else
{
_service = AdminCrmService;
}
return _service;
}
}
I think, the problem is not due to code because it works fine for some users and is only slow for new users. I have compared the new/old users in the CRM and in the AD and everything seems equal. Can someone knows how the authentication is done by the CRM ? Do you have an other idea ?