Cast generic Entity data type to a CustomEarlyBoundEntity data type

  Kiến thức lập trình

I am developing a Plug-In for a Dynamics CRM environment for which I have available Early Bound Classes.

on the first lines of my code I have a variable on which is saved an object of type “Entity” and I need to cast it into a “Contact” data type, from the early bound classes. I have done so :

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
  Entity targetEntity = (Entity)context.InputParameters["Target"];

  if (targetEntity.LogicalName != Contact.EntityLogicalName)
      return;

  Contact updatingContact = targetEntity.ToEntity<Contact>();

Problem is, object “updatingContact” is filled with null values. No values gets passed from “targetEntity” to “updatingContact”.

I thought this was the right way how to cast variables into different compatible types.

Can anyone tell me what´s wrong?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT