如何获取与当前实体相关的所有注释的guid列表(或例如集合)?
我知道它在某种程度上与service.Retreive(...)有关,但无法生成有效的代码。
附加1:
public void Execute(IServiceProvider serviceProvider)
{
Entity entity = null;
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (entity.Contains("new_parentopportunity"))
{
try
{
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Guid projectGuid = entity.Id;
Guid oppGuid = ((EntityReference)entity["new_parentopportunity"]).Id;
for (int i = 0; i < 100; i++) //Instead of 100, I'll place obtained collection.Length
{
Entity opp = service.Retrieve("", oppGuid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); //RETREIVE ENTITY NOTE HERE
var temop = CreateNoteAttachment(opp);
service.Create(temp);
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
private Entity CreateNoteAttachment(Entity oppNote)
{
//some code here
}
更新1:
我也是在查询中写的,你能看一下吗,那里的一切都很好吗? PasteBin
答案 0 :(得分:2)
查询相关注释的两种方法:
早期约束:
var notes =
service.AnnotationSet.Where(annotation => annotation.Opportunity_Annotation.Id == entity.Id)
.Select(annotation => annotation.Id)
.ToList();
FetchXml:
var fetchXml = string.Format("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='annotation'>" +
"<attribute name='annotationid' />" +
"<filter type='and'>"+
"<condition attribute='objectid' operator='eq' value='{0}'/>"+
"</filter>"+
"</entity>" +
"</fetch>", entity.Id);
var response = service.RetrieveMultiple(new FetchExpression(fetchXml));
var notes = response.Entities;