创建实体记录的不同版本,我是用SDK先查询这条记录的entity 实例,然后修改这个记录的entity.Id 用Create方法创建结果报错:Cannot insert duplicate key.
//entityItem为查询出来的记录,实体为电子邮件 email
Entity copyEntityItem = new Entity(entityItem.LogicalName);
copyEntityItem = entityItem;
//copyEntityItem.Attributes = entityItem.Attributes;
if (copyEntityItem.Contains(ActivityId))
{
copyEntityItem.Attributes.Remove(ActivityId);
}
if (copyEntityItem.Attributes.Contains(entityItem.LogicalName + "id"))
{
copyEntityItem.Attributes.Remove(entityItem.LogicalName + "id");
}
copyEntityItem.Id = Guid.NewGuid();
//copyEntityItem.Attributes[item.ReferencingAttribute] = new EntityReference(target.LogicalName, copyId);
service.Create(copyEntityItem);
windows live Id :hellohongfu@hotmail.com