如何从实体中检索记录或视图

本文关键字:记录 视图 检索 实体 | 更新日期: 2023-09-27 18:14:22

我想从这些属性中获取值:

class Program
{
    private static OrganizationService _orgService;
     private static void Main(string[] args)
     {
         ClientCredentials cre = new ClientCredentials();
         cre.UserName.UserName = "login";
         cre.UserName.Password = "password";
         Uri serviceUri = new Uri("some_adress");
         OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, cre, null);
         proxy.EnableProxyTypes();
         IOrganizationService service = (IOrganizationService) proxy;
         retrieveEntityRequest = new RetrieveEntityRequest
         {
             EntityFilters = EntityFilters.All,
             LogicalName = "new_sms_parameters",
             RetrieveAsIfPublished = true
         };
         retrieveEntityResponse = (RetrieveEntityResponse) service.Execute(retrieveEntityRequest);
         currentEntity = retrieveEntityResponse.EntityMetadata;
         // Attributes

         foreach (AttributeMetadata allattributes in currentEntity.Attributes)
         {
             Console.WriteLine("SMS Parameters: " +   allattributes.LogicalName);
         }
     }
}

这里我连接到CRM并获得属性名称,但我不知道如何获得这些值。接下来我能做什么?

如何从实体中检索记录或视图

RetrieveEntityRequest用于获取描述实体的元数据,例如;字段数、字段类型,如string、int等

如果你想获得记录信息,你需要使用Retrieve来获取单个记录的Id,或retrievmultiple来获取多个记录基于查询。

查看上面的链接以获得完整的示例,但要有效:

ColumnSet attributes = new ColumnSet(new string[] { "name", "ownerid", "address1_postalcode" });
account = service.Retrieve(account.LogicalName, accountId, attributes);
String postcode = account["address1_postalcode"];
String alsoPostcode = account.GetAttributeValue<String>("address1_postalcode");