zoukankan      html  css  js  c++  java
  • Dynamics 365-为什么查到的Record的Id是Guid初始值

      通过代码查询CRM数据,这个是开发经常会碰到的情况,获取返回的EntityCollection之后,我们会拿Entity.Id做进一步操作。笔者最近碰到的情况,是Entity.Id是个初始值。先上一段FetchXml:

    private string FetchAccountFromContact = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
        "<entity name='account'>" +
          "<attribute name='name' />" +
          "<attribute name='new_bdrassigned' />" +
          "<attribute name='ownerid' />" +
          "<order attribute='name' descending='false' />" +
          "<link-entity name='contact' from='parentcustomerid' to='accountid' link-type='inner' alias='ac'>" +
            "<filter type='and'>" +
              "<condition attribute='contactid' operator='eq' value='{0}' />" +
            "</filter>" +
          "</link-entity>" +
        "</entity>" +
      "</fetch>";

    查询Code:

    FetchAccountFromContact = string.Format(FetchAccountFromContact, contactId);
    FetchExpression expression = new FetchExpression(FetchAccountFromContact);
    EntityCollection accounts = service.RetrieveMultiple(expression);

    这套查询操作,初看没什么问题,但是当用最后的accounts,来做进一步的处理的时候,问题来了:

    Id是Guid的初始值,并不是我们期望的真正的Record的Id。

    问题原因:

    在FetchXml那里,我们还需要加一个attribute,就是accountid。

    private string FetchAccountFromContact = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
        "<entity name='account'>" +
          "<attribute name='name' />" +
          "<attribute name='accountid' />" +
          "<attribute name='new_bdrassigned' />" +
          "<attribute name='ownerid' />" +
          "<order attribute='name' descending='false' />" +
          "<link-entity name='contact' from='parentcustomerid' to='accountid' link-type='inner' alias='ac'>" +
            "<filter type='and'>" +
              "<condition attribute='contactid' operator='eq' value='{0}' />" +
            "</filter>" +
          "</link-entity>" +
        "</entity>" +
      "</fetch>";

    然后再次查询就会发现Id有值了

  • 相关阅读:
    Retrofit2.0+OkHttp设置统一的请求头(request headers)
    Retrofit、Okhttp使用小记(cookie,accesstoken,POST
    quartz持久化部署实现
    支付宝支付-常用支付API详解(查询、退款、提现等)
    支付宝支付-提现到个人支付宝
    Git 版本还原命令
    CEF JS实现获取剪贴板图片的DataURL
    CEF 自定义用户协议(scheme)实现以二进制流的方式显示图片、视频、音频
    CEF C++调用前端js方法展示传递过来的图片数据
    C++读写图片数据转成Base64格式
  • 原文地址:https://www.cnblogs.com/yobyron/p/9282788.html
Copyright © 2011-2022 走看看