简体   繁体   English

Dynamics 365 FakeXrm“用户设置”实体错误

[英]Dynamics 365 FakeXrm "usersettings" entity error

I have this piece of code in my Dynamics 365 plugin,我的 Dynamics 365 插件中有这段代码,

 private int? RetrieveCurrentUsersSettings(IOrganizationService service)
    {
        var currentUserSettings = service.RetrieveMultiple(
            new QueryExpression("usersettings")
            {
                ColumnSet = new ColumnSet("timezonecode"),
                Criteria = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression("systemuserid", ConditionOperator.EqualUserId)
                    }
                }
            }).Entities[0].ToEntity<Entity>();

        return (int?)currentUserSettings.Attributes["timezonecode"];
    }

and I am writing a UnitTest for it with FakeXrm, and while debugging I am getting an error, in this query expression.我正在用 FakeXrm 为它编写一个 UnitTest,在调试时我在这个查询表达式中遇到错误。

Here is my fake Xrm code.这是我的假 Xrm 代码。

  Entity systemUser = new Entity("systemuser");
        systemUser.Id = Guid.NewGuid();

        Entity userSettings = new Entity("usersettings");
        userSettings.Id = Guid.NewGuid();
        userSettings["timezonecode"] = 71;
        userSettings["systemuserid"] = systemUser.ToEntityReference();

        fakedContext.Initialize(new List<Entity>()
        {
            workOrder, owner, invoiceNote, userSettings
        });

The question is, how to create usersettings entity in FakeXrm and provide proper attributes to it.问题是,如何在 FakeXrm 中创建usersettings实体并为其提供适当的属性。

I am glad that you followed my suggestion to ask the question on StackOverflow.我很高兴您按照我的建议在 StackOverflow 上提问。

Anyway you should have pointed out that you asked the same question on GitHub on the FakeXrmEasy repository and that the solution was provided there with this answer .无论如何,您应该指出您在 GitHub 上的FakeXrmEasy存储库上提出了相同的问题,并且在那里提供了此答案的解决方案。

Long story short, the problem with your UnitTest was that you were missing fakedContext.CallerId = systemUser.ToEntityReference();长话短说,你的 UnitTest 的问题是你缺少fakedContext.CallerId = systemUser.ToEntityReference(); and that was needed because you were using ConditionOperator.EqualUserId in your query.这是必需的,因为您在查询中使用了ConditionOperator.EqualUserId

Best Regards, Betim Beja.最好的问候,贝蒂姆贝贾。

I have found a solution我找到了解决办法

           Entity systemUser = new Entity("systemuser");
            systemUser.Id = Guid.NewGuid();
            fakedContext.CallerId = systemUser.ToEntityReference();
            IOrganizationService service = fakedContext.GetOrganizationService();
            Entity userSettings = new Entity("usersettings");
            userSettings.Id = Guid.NewGuid();
            userSettings["timezonecode"] = 71;
            userSettings["systemuserid"] = systemUser.ToEntityReference();

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

相关问题 使用 CorrelationId 上下文更新 Dynamics 365 中的实体 - Updating entity in Dynamics 365 using CorrelationId context 使用 api 在 Dynamics 365 中创建批量删除作业会导致错误提示实体不支持同步批量删除 - Creating a bulk delete job in Dynamics 365 using the api results in an error saying synchronous bulk delete is not supported for the entity MS Dynamics 365 CRM 在线 - 转储实体 - MS Dynamics 365 CRM online - dump entity Dynamics 365 - 为“审计”实体注册“创建”步骤 - Dynamics 365 - Register a 'Create' step for 'audit' entity Dynamics 365 (CRM) 9.1 版在线 C# 代码错误:实体 ID 必须与属性包中设置的值相同 - Dynamics 365 (CRM) Version 9.1 online C# code Error: Entity Id must be the same as the value set in property bag 如何在Dynamics 365 SDK中检索没有向导的实体? - How to retrieve a Entity without Guid in Dynamics 365 SDK? 如何访问Dynamics 365插件中的自定义实体字段 - How to access Custom Entity fields in Dynamics 365 plugin 在 Microsoft Dynamics 365 CRM 中导入解决方案时在实体上注册插件 - Register a Plugin on a Entity when a Solution is imported in Microsoft Dynamics 365 CRM C# Memory 从 Dynamics 365 检索实体详细信息 - C# Out of Memory retrieving entity details from Dynamics 365 尝试 Web API Dynamics 365 CRM - 403-禁止错误 - Trying Web API Dynamics 365 CRM - 403-Forbidden error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM