Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从实体检索记录或视图?_C#_.net_Dynamics Crm 2013 - Fatal编程技术网

C# 如何从实体检索记录或视图?

C# 如何从实体检索记录或视图?,c#,.net,dynamics-crm-2013,C#,.net,Dynamics Crm 2013,我想从以下属性中获取值: class Program { private static OrganizationService _orgService; private static void Main(string[] args) { ClientCredentials cre = new ClientCredentials(); cre.UserName.UserName = "login"; cre.Use

我想从以下属性中获取值:

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
用于获取描述实体的元数据;字段数量、字段类型,如字符串、int等

如果要获取记录信息,则需要使用以按Id获取单个记录,或基于查询获取多个记录

查看上面的链接以获取完整的示例,但实际上:

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");
ColumnSet attributes=newcolumnset(新字符串[]{“name”、“ownerid”、“address1\u postalcode”});
account=service.Retrieve(account.LogicalName、accountId、attributes);
字符串邮政编码=帐户[“地址1\u邮政编码”];
字符串alsoPostcode=account.GetAttributeValue(“address1_postalcode”);

您有返回类型void;分别更改为适当的返回类型,如字符串数组和返回。如何获取id?它来自CRM中的记录,所以有很多不同的方法获取它。使用
RetrieveMultiple
可以按其他属性值进行搜索。