ruijian 发表于 2012-12-29 11:22:56

使用ViewFields提升SPQuery查询性能

<div id="cnblogs_post_body">        用SPquery查询文档库文件,当使用了Scope=\"Recursive\后,性能大幅下降,通过开发人员面板看到我的webpart查询数据耗时:EnsureListItemsData (196.45 ms)
       在查询语句中加入ViewFields限制,只取需要用到的字段,查询时间能缩短将近一半:EnsureListItemsData (96.47 ms)
<div id="codeSnippetWrapper">   <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">      1: sPQuery.ViewFields = string.Concat(       2:                  "<FieldRef Name='FileLeafRef' />",       3:                  "<FieldRef Name='EncodedAbsUrl' />",       4:                  "<FieldRef Name='Modified' />",       5:                  "<FieldRef Name='File_x0020_Type' />",       6:                  "<FieldRef Name='LinkTitle' />",       7:                  "<FieldRef Name='ServerUrl' />",       8:                  "<FieldRef Name='PermMask' />");                     9: sPQuery.ViewFieldsOnly = true;
页: [1]
查看完整版本: 使用ViewFields提升SPQuery查询性能