我的插件触发“创建”-xxx-Entity。在ServiceContextI中,只有属于该实体的注释。但是,例如,我想要CRM中的所有笔记或属于另一个不在ServiceContext中的实体的所有记录。我怎样才能找回它?
var ServiceContext = new OrganizationServiceContext(service);
var notes = from n in ServiceContext.CreateQuery("annotation")
where n["objectid"] == new EntityReference("xxx", xxx.Id)
select n;
OrganizationServiceContext可以无限制地查询任何实体。您可以使用相同的查询,只需删除where子句,您将获得所有注释:
var query = from n in ServiceContext.CreateQuery("annotation")
select n;
var allNotes = query.ToList();
或者,对于与另一条记录相关的注释:
var query = from n in ServiceContext.CreateQuery("annotation")
where n.GetAttributeValue<EntityReference>("objectid").Id.Equals(myObjectId)
select n;
对于具有附件的注释,除非您需要documentbody
,否则将其排除在查询之外可以加快速度。