Bas*_*sie 2 c# linq sharepoint lambda
我有一些代码调用SharePoint Managed Metadata Service,它启动如下:
var clientContext = new ClientContext("http://mysharepointsite/")
{ AuthenticationMode = ClientAuthenticationMode.Default};
var taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
var termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
Run Code Online (Sandbox Code Playgroud)
我没有问题.但是,在此之后我们有:
clientContext.Load(termStore,
store => store.Name,
store => store.Groups.Include(
group => group.Name,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Terms.Include(
term => term.Name)
)
)
);
Run Code Online (Sandbox Code Playgroud)
谁能帮助我了解这里发生了什么?
起初我认为这是某种LINQ查询,但后来我希望该类具有该行using System.Linq;,但它没有.
我只是注意到在Visual Studio中有一些IntelliSense,它表示调用的结构如下: void ClientruntimeContext.Load<T>(T clientObject, params System.Linq.Expressions.Expression<Func<T, object>>[] retrievals)- 这使得它似乎以某种方式使用Linq
我知道代码以某种方式从给定的sharepoint站点"加载"托管元数据服务中的术语库数据,但我不太清楚该语法到底在做什么.
我从这里得到了代码示例,它完全符合我的要求,但如果我真的理解了这种语法,我会觉得更舒服!
文档也没有特别的帮助,因为它只是将Load()s参数定义为<T>,可以是任何东西!
非常感谢任何建议或推荐阅读,谢谢!
ClientRuntimeContext.Load<T> 方法此方法的第二个参数指定应使用lambda表达式检索目标客户端对象(第一个参数)的哪些属性.
例子
在下面的查询,除了所有属性集合性能如TermStore.Groups的TermStore客户对象将被检索
ctx.Load(termStore);
Run Code Online (Sandbox Code Playgroud)
在下一个查询中,将仅为客户端对象检索显式指定的属性列表(TermStore.Name,TermStore.Groups):TermStore
ctx.Load(termStore, store => store.Name, store => store.Groups);
Run Code Online (Sandbox Code Playgroud)
接下来的问题出现了,如何指定要检索的集合客户端对象的哪些属性,Include<TSource>(IQueryable<TSource>, \[\])方法方法来到这里拯救.
Include<TSource>(IQueryable<TSource>, \[\]) 方法此方法用于限制从对象集合返回的属性(出于性能目的)
例
以下表达式
ctx.Load(termStore, store => store.Groups.Include( g => g.Name));
Run Code Online (Sandbox Code Playgroud)
告诉构造查询以返回TermStore客户端对象,其中包含TermStore.Groups属性但不包含客户端对象的默认属性Group,仅Group.Name属性.
| 归档时间: |
|
| 查看次数: |
3947 次 |
| 最近记录: |