如何确定 PartyId 的实体类型?

How can the Entity type of a PartyId be determined?

使用 Dynamics CRM 2011。我正在学习 ActivityPartys。

由于ActivityParty的PartyId是一个EntityReference,为了设置PartyId,您需要知道实体类型。

我正在尝试使用与现有 phone 呼叫相同的收件人来创建新的 PhoneCall(在插件中)。我可以使用 LINQ 从 ActivityPartySet 中检索接收者的 PartyId Guid,但是我如何确定实体类型,它可以是帐户或联系人?

反之,是否可以在不知道EntityLogicalName的情况下设置PartyId?

更新:

感谢您的回复,但要么是我误解了您,要么您误解了我要确定的内容。这是我的代码:

 // Get the oldPhoneCall's To ActivityParty list:
                    EntityCollection Recipients = oldPhonecall.GetAttributeValue<EntityCollection>("to");

                    // Use the first one to find the partyId 
                    // Need to do it this way because we don't know if partyId points to an Account or a Contact:
                    Guid activityPartyId = Recipients.Entities[0].Id;
                    var activityParty2 = new Xrm.ActivityParty();

                    context.GetWorkflowHelper().serviceContext.ClearChanges();

                    var queryParty = from ap in context.GetWorkflowHelper().serviceContext.ActivityPartySet
                                     where ap.ActivityPartyId.Equals(activityPartyId)
                                    select new { ap.PartyId, ap.LogicalName };
                    foreach (var party in queryParty)
                    {
                        activityParty2.PartyId = new EntityReference(party.LogicalName, party.PartyId.Id);
                    }

我发现在foreach中,party.LogicalName是ActivityParty。这不是 oldphonecall 的接收者的实体类型,在我的测试用例中是 Contact 但在其他情况下是 Account。

如何确定该实体的逻辑名称?我哪里做错了?

更新2:

在 SQL 中,我可以看到字段 PartyObjectTypeCode 并且我知道我可以将其映射到实体类型(其中 1 = 帐户,2 = 联系人等)但是当我查询 ActivityPartySet 时,没有这样的字段似乎存在。

更新 3:

知道了 -

 foreach (var party in queryParty)
                    {
                        activityParty2.PartyId = new EntityReference(party.PartyId.LogicalName, party.PartyId.Id);
                    }

how can I determine the Entity Type, which could be either Account or Contact?

PartyId 的类型 EntityReference where LogicalName 将为您提供相关的实体类型。

var entityLogicalName = context.EmailSet.FirstOrDefault().To.FirstOrDefault().PartyId.LogicalName

Conversely, is it possible to set the PartyId without knowing the EntityLogicalName?

否,在设置 CRM 实体引用时,Id 和 LogicalName 都是必填字段。

为了设置 PartyId,您需要知道实体的 LogicalName。

您没有 post 代码,但如果您能够从收件人那里检索到 Id,您还可以检索到 LogicalName(它们存储为 EntityReference)