【问题标题】:CAML query with Joins and where condition together使用 Joins 和 where 条件一起的 CAML 查询
【发布时间】:2016-07-02 05:05:40
【问题描述】:

我有一个场景,请帮我构建一个 caml 查询。

Sharepoint List 1 有列:

  • ID
  • 客户名称
  • 分公司

Sharepoint List 2 有列:

  • 身份证
  • Cust_ID
  • 产品名称
  • 数量
  • 价值

ID(list 1)=Cust_ID(list 2)

假设一个人从一个特定的分支登录,首先检查当前登录分支。 然后在 asp 网格视图 中显示 Sharpeoint 列表 2 的所有内容,但仅显示当前分支的内容(从列表 1 中获取的分支)。表示需要连接查询,以及检查当前登录分支的where条件。

请帮我建立一个同样的 caml 查询,我尝试了一些 caml 查询构建器,但没有得到结果。

【问题讨论】:

    标签: c# asp.net visual-studio sharepoint caml


    【解决方案1】:

    您不能加入。在这种情况下,如果有 1 个用户或两者都有多个分支,则必须查找分支到 List2 您可以创建模型,例如,您应该使用 ID 和分支查询第二个列表,因此如果您没有分支名称或分支代码,您可以使用该用户获取所有数据,将该数据加载到模型,您可以从模型中选择您想要的任何内容

    public class AllDatas
    {
    public AllDatas(SplistItem item)
    {
    CustomerName = item["CustomerName"]
    Branch = item["Branch"]
    Product = item["Product"]
    .
    .
    .
    }
    
    string CustomerName {get;set}
    string Branch {get;set;}//this can be int what evet you want
    string Product Name {get;set}
    int Quantity {get;set}
    int Value {get;set}
    }
    

    我假设你有分支和 ID,所以如果你没有 ID 并且只有分支,那么你应该使用 caml 列出一个分支来获取 ID 以查询到 List2,你可以使用相同的 caml 和从 list1 获取数据的方式。

    using(SPSite oSiteCollection = new SPSite("http://Server_Name"))
    {
        using(SPWeb oWebsite = oSiteCollection.OpenWeb("Website_URL"))
        {
    
    SpList list2Col = oWebsite.Lists["List2"];
    SPListItemCollection list2 = list2Col.GetItems("<Query><Where><Eq><FieldRef Name='Cust_ID' /><Value Type='Number'>"Your Customer ID From List1"</Value></Eq></Where></Query>");
    List<AllDatas> myDatas = new List<AllDatas>();
          foreach(SpListItem item in list2)
    {
    myDatas.add(new AllDatas(item));
    }
    
    var resultWithCorrectBranch = myDatas.Where(t=>t.Branch=="something"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 2012-11-23
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      相关资源
      最近更新 更多