为什么IOrganizationService.Update()返回“Microsoft Dynamics CRM中不存在指定的记录类型。”?

时间:2014-01-31 18:39:47

标签: dynamics-crm-2011

在早期绑定的自定义实体(已检索的记录)中更新记录的调用将返回上述消息。代码片段如下(大量检测,但我将把所有内容都保留在内,因为我是CRM代码的新手,可能会删除相关内容)

// retrieve and update ContactFact record -

string strcontactFactId = reader["contactFactId"] == DBNull.Value ? string.Empty : (string)reader["contactFactId"];
string strcontactId = reader["contactId"] == DBNull.Value ? string.Empty : (string)reader["contactId"];
whereAmI = "retrieved strcontactId = " + strcontactId;
string straccountId = reader["accountId"] == DBNull.Value ? string.Empty : (string)reader["accountId"];

Guid contactFactId;
Guid contactId;
Guid accountId;
Guid.TryParse(strcontactFactId, out contactFactId);
whereAmI = "try to generate contactId from " + strcontactId;
Guid.TryParse(strcontactId, out contactId);
whereAmI = "generated contactId = " + contactId.ToString();
Guid.TryParse(straccountId, out accountId);

int score = reader.GetInt32(3);

whereAmI = "try to retrieve contactFact " + contactFactId.ToString();
sbtls_contactfact contactFact = (sbtls_contactfact)service.Retrieve("sbtls_contactfact", contactFactId, columnSet);  // xx prob don't need to retrieve current values
whereAmI = "try to set sbtls_ContactId to " + contactId.ToString();
contactFact.sbtls_ContactId = contactId == Guid.Empty ? null : new EntityReference("Contact", contactId);
whereAmI = "successfully set sbtls_ContactId to " + contactId.ToString();
contactFact.sbtls_AccountId = accountId == Guid.Empty ? null : new EntityReference("Account", accountId);
contactFact.sbtls_Score = score;
contactFact.sbtls_Fact = "Updated with contactId " + strcontactId + " parsed to GUID " + contactId.ToString();
whereAmI = "about to update";
service.Update(contactFact);
whereAmI = "updated";

1 个答案:

答案 0 :(得分:1)

您需要更改这两行:

contactFact.sbtls_ContactId = contactId == Guid.Empty ? null : new EntityReference("Contact", contactId);

contactFact.sbtls_AccountId = accountId == Guid.Empty ? null : new EntityReference("Account", accountId);

要对EntityReference.LogicalName值使用小写,请将其显示为:

contactFact.sbtls_ContactId = contactId == Guid.Empty ? null : new EntityReference("contact", contactId);

contactFact.sbtls_AccountId = accountId == Guid.Empty ? null : new EntityReference("account", accountId);

逻辑名称区分大小写,应为小写。