[英]Dynamics CRM 2015 Online: cannot retrive custom fields
以下代碼在WriteLine()上引發KeyNotFoundException:
CrmConnection crmConnection = CrmConnection.Parse(_connectionString);
using (OrganizationService service = new OrganizationService(crmConnection))
{
QueryExpression query = new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet("fullname", "new_customer_num", "new_is_customer"),
};
EntityCollection contacts = service.RetrieveMultiple(query);
if (contacts.Entities.Count > 0)
{
foreach (var e in contacts.Entities)
{
System.Diagnostics.Debug.WriteLine(
e.Attributes["fullname"].ToString() + "; " +
e.Attributes["new_is_customer"].ToString());
}
}
}
我已經向聯系人實體添加了new_customer_num和new_is_customer(必填)字段。 如果我故意拼錯它們,則會在service.RetrieveMultiple(query);處拋出FaultException。 所以我猜CRM會“知道”我的自定義字段。 那為什么查詢結果中不包括它們呢?
好吧,要使其正常工作,我必須添加一個條件:
QueryExpression query = new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet("fullname", "ht_customer_num", "ht_is_customer"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "new_is_customer",
Operator = ConditionOperator.Equal,
Values = { true }
},
},
}
};
ColumnSet的SDK文檔說查詢僅返回非null值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.