我发现这个片段提供了一个名为annotation
. 我找不到 在指令中XrmServicesContext
声明的类。using
有谁知道这是什么鬼?
private static void AddNoteToContact(IOrganizationService service, Guid id)
{
Entity annotation = new Entity();
annotation.LogicalName = "annotation";
using (var crm = new XrmServicesContext(service))
{
var contact = crm.ContactSet.Where(c => c.ContactId == id).First();
Debug.Write(contact.FirstName);
annotation["createdby"] = new EntityReference("systemuser", new Guid("2a213502-db00-e111-b263-001ec928e97f"));
annotation["objectid"] = contact.ToEntityReference();
annotation["subject"] = "Creato con il plu-in";
annotation["notetext"] = "Questa note è stata creata con l'esempio del plug-in";
annotation["ObjectTypeCode"] = contact.LogicalName;
try
{
Guid annotationId = service.Create(annotation);
crm.AddObject(annotation);
crm.SaveChanges();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
// var note = new Annotation{
//Subject ="Creato con il plu-in",
//NoteText ="Questa note è stata creata con l'esempio del plug-in",
//ObjectId = contact.ToEntityReference(),
//ObjectTypeCode = contact.LogicalName
};
}