简体   繁体   English

CRM2011-一些用户的表现不佳

[英]CRM2011 - Bad performances for some users

I have troubles with CRM2011: 我在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. 当代码尝试使用IOrganizationService通过linq查询从数据库检索数据时,在Active Directory中创建的所有新用户的性能均不佳。 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) Activity是一个ActivityPointer,我尝试获取与其链接的所有附件:(最慢的部分是当我尝试使用ActivityAttachments属性的一项时)

foreach (var attachment in activity.ActivityAttachments)
                        {
                             //Do stuff
                        }

ActivityAttachments is the result of a linq query using the datacontext ActivityAttachments是使用datacontext进行linq查询的结果

        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 而datacontext是我的数据模型-为每个用户创建并存储为我的crmservice,我的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. 我已经比较了CRM和AD中的新老用户,一切似乎都一样。 Can someone knows how the authentication is done by the CRM ? 有人可以知道CRM如何进行身份验证吗? Do you have an other idea ? 您还有其他想法吗?

From your comments about how new users are suffering the same exceptions as old users, except far more of them, I think this is the cause of your performance issues for new users. 从您对新用户如何遭受与旧用户相同的例外的评论(除了更多)来看,我认为这是新用户性能问题的原因。

Find the cause of the exceptions and fix them, and your performance should improve. 找到导致异常的原因并加以解决,您的性能应该得到改善。

Read this http://blogs.msdn.com/b/ricom/archive/2006/09/25/771142.aspx 阅读此http://blogs.msdn.com/b/ricom/archive/2006/09/25/771142.aspx

and this 和这个

How expensive are exceptions in C#? C#中异常的代价是多少?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM