我有一个托管元数据服务,它有一个包含术语集和术语的术语组。
我对SharePoint查询很陌生,目前正在做以下工作:
对于上述每一个步骤,我都要在客户端上下文上加载和执行一个查询。
代码:
var siteUrl = ConfigHelper.GetValue("SharepointSiteUrl");
var clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new NetworkCredential(ConfigHelper.GetValue("ServiceAccountLogonName"), ConfigHelper.GetValue("ServiceAccountPassword"));
var taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
taxonomySession.UpdateCache();
clientContext.Load(taxonomySession, ts => ts.TermStores);
clientContext.ExecuteQuery();
if (taxonomySession.TermStores.Count == 0)
{
throw new InvalidOperationException("The Taxonomy Service is offline or missing");
}
var termStore = taxonomySession.TermStores[1];
clientContext.Load(termStore);
clientContext.ExecuteQuery();
var termSet = termStore.GetTermSet(new Guid("f40eeb54-7c87-409d-96c7-75ceed6bff60"));
clientContext.Load(termSet);
clientContext.ExecuteQuery();
var terms = termSet.GetAllTerms();
clientContext.Load(terms);
clientContext.ExecuteQuery();
foreach (var term in terms)
{
clientContext.Load(term, t => t.Id, t => t.Name);
clientContext.ExecuteQuery();
}如何优化这个术语的SharePoint查询?
发布于 2015-05-15 11:06:23
指定示例的主要问题是向服务器提交了一组中间请求,因此主要优化如下:
因为如果您的目标是只检索特定术语集的术语,那么可以对示例进行优化,如下所示:
var taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
var termSet = termStore.GetTermSet(termSetId);
var terms = termSet.GetAllTerms();
ctx.Load(terms, tcol => tcol.Include(t => t.Id,t => t.Name));
ctx.ExecuteQuery();一些建议
TermStoreCollection.GetByName或TermStoreCollection.GetById方法,而不是按索引获取TermStore,因为在后面的情况下,TermStoreCollection必须先初始化TaxonomySession.GetDefaultSiteCollectionTermStore method发布于 2015-05-15 10:12:48
这边请
var taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
taxonomySession.UpdateCache();
TermStore ts = taxonomySession.TermStores.GetById(termStoreId);
TermSet set = ts.GetTermSet(termSetId);
TermCollection terms = set.GetAllTerms();
ctx.Load(terms, t=>t.IncludeWithDefaultProperties(term=>term.Name, term=>term.Id));
ctx.ExecuteQuery();https://stackoverflow.com/questions/30252443
复制相似问题