using (SPSite site = new SPSite(SiteUrl)){ using (SPWeb web = site.RootWeb) { SPquery query = new SPquery(); //Joins属性,这里有INNER和left两种方式连接,均可查询,而且支持多表连接; query.Joins = "<Join Type=‘INNER‘ ListAlias=‘City‘>" + "<Eq>" + "<FIEldRef name=‘Location‘ RefType=‘ID‘/>" + "<FIEldRef List=‘City‘ name=‘ID‘/>" + "</Eq>" + "</Join>"; //设置关联的查阅项字段 query.ProjectedFIElds = "<FIEld name=‘CustomCityID‘ Type=‘Lookup‘ " + "List=‘City‘ ShowFIEld=‘CityID‘/>";<FIEld name=‘CustomMark‘ Type=‘Lookup‘ List=‘City‘ ShowFIEld=‘Mark‘/>"; //设置需要显示的字段 query.VIEwFIElds = "<FIEldRef name=‘Title‘/>" + "<FIEldRef name=‘Location‘/>" + "<FIEldRef name=‘CustomCityID‘/>";"<FIEldRef name=‘CustomMark‘/>"; splist List = web.GetList(Listname); splistItemCollection itemcoll = List.GetItems(query); foreach (splistItem item in itemcoll) { SPFIEldLookupValue Location = new SPFIEldLookupValue(item["Location"].ToString()); SPFIEldLookupValue CustomCityID = new SPFIEldLookupValue(item["CustomCityID"].ToString()); Console.Writeline("ID:" + item.ID.ToString() + " Title:" + item["Title"].ToString() + " Location:" + Location.LookupValue + " CustomCityID:" + CustomCityID.LookupValue); } }}9、同时为代码的ProjectedFIElds多添加Mark的字段属性,如下图:query.ProjectedFIElds ="<FIEld name=‘CustomCityID‘ Type=‘Lookup‘ List=‘City‘ ShowFIEld=‘CityID‘/><FIEld name=‘CustomMark‘ Type=‘Lookup‘ List=‘City‘ ShowFIEld=‘Mark‘/>"; 10、同时为显示属性加入CustomMark字段,如下图:query.VIEwFIElds = "<FIEldRef name=‘Title‘/>" + "<FIEldRef name=‘Location‘/>" + "<FIEldRef name=‘CustomCityID‘/>" + "<FIEldRef name=‘CustomMark‘/>"; 输出添加CustomMark字段的值,如下:SPFIEldLookupValue CustomMark = new SPFIEldLookupValue(item["CustomMark"].ToString());Console.Writeline("CustomMark:" + CustomMark.LookupValue)附:列表结构 列表一:City 字段:Title(默认字段,单行文本,作为Address关联的查阅项) CityID(数字类型,作为Address关联的查阅项) Mark(单行文本,作为多表查询的测试字段) 列表二:Address 字段:Title(默认) Location(查阅项,关联City列表的Title) CustomCityID(查阅项,关联City列表的CityID)附:参考链接 http://social.msdn.microsoft.com/Forums/sharepoint/zh-CN/866a49fd-0656-4a8a-9e11-36eeb4401005/sharepoint-2010-caml-List-joins http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spquery.joins.aspx总结
以上是内存溢出为你收集整理的Caml 多表关联查询全部内容,希望文章能够帮你解决Caml 多表关联查询所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)