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
可以按其他属性值进行搜索。