C# MSCRM 4使用InitializeFromRequest将标准实体转换为自定义实体
我正在尝试使用以下代码,使用InitializeFromRequest将order和orderdetail行转换为自定义实体及其子行:C# MSCRM 4使用InitializeFromRequest将标准实体转换为自定义实体,c#,dynamics-crm,dynamics-crm-4,C#,Dynamics Crm,Dynamics Crm 4,我正在尝试使用以下代码,使用InitializeFromRequest将order和orderdetail行转换为自定义实体及其子行: public void Convert(Guid FromEntityId, string FromEntityName, string ToEntityName) { try { // Set up the CRM Service. CrmService _service = GetCrmService();
public void Convert(Guid FromEntityId, string FromEntityName, string ToEntityName)
{
try
{
// Set up the CRM Service.
CrmService _service = GetCrmService();
InitializeFromRequest req = new InitializeFromRequest();
req.EntityMoniker = new Moniker(); // this is the very thing that does the job.
req.EntityMoniker.Id = FromEntityId;
req.EntityMoniker.Name = FromEntityName;
req.TargetEntityName = ToEntityName; //contact for our example req.
req.TargetFieldType = TargetFieldType.ValidForCreate;
InitializeFromResponse rps = (InitializeFromResponse)_service.Execute(req);
//now the lead is converted to a contact, and you can see it in contacts.
Guid entityId = _service.Create(rps.Entity);
lblMsg.Text = "Done ID:" + entityId.ToString();
}
catch (System.Web.Services.Protocols.SoapException se)
{
lblMsg.Text = "soap:" + se.Detail.InnerText;
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
}
现在我可以创建一个自定义实体,但是所有属性都是空的,尽管我在Realationship中设置了映射字段
我遗漏了什么或做错了什么?将标准实体转换为自定义实体时,需要将ReturnDynamicEntities设置为true