LINQ to sharepoint。加入列表帮助

时间:2011-05-06 21:30:14

标签: linq sharepoint-2010 linq-to-entities

我目前正在使用SharePoint 2010,而在我的业务层中,我使用的是LINQ to SharePoint。我使用SPMetal生成了所有的Entity类。

我们正在创建一个图书馆系统,我的系统有2个列表。第一个是贡献,第二个是贡献者。每个贡献者都包含对贡献列表的引用(PrimaryISBN参考)。贡献列表包含书籍列表,PrimaryISBN在此列表中不是唯一的。

贡献

ID  PrimaryISBN      TITLE      
1   PRIM1            HardcoverLOTR      
2   PRIM1            AudioBookLOTR      
3   PRIM2            HardcoverHP        

贡献者

ID  Name  PrimaryISBNLookup
1   ABC   PRIM1
2   DEF   PRIM2

我目前正在尝试根据名称获取特定用户提供的所有图书。 我的查询是这样的

var result = from _contributor in data.contributor
             where _contributor.Name= "ABC"
             select new Book
            {
               Title = contributor.PrimaryISBNLookup.Title
            }

我目前面临的问题是检索具有相同ISBN但标题不同的记录(每种格式都有一个标题,即音频书将有一个标题,而同一本书的精装本将有不同的标题)。 这个查询只返回1条记录,即使我的系统中有2条记录,即在记录插入贡献者列表期间我不得不插入ID(在贡献中)的记录。

非常感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

根据我的理解,您尝试实现一个简单的连接,如下所示:

var results = from _contributor in data.contributor
              join _contribution in data.contribution
              on _contributor.PrimaryISBNLookup equals _contribution.PrimaryISBN
              where _contributor.Name == "ABC"
              select new Book
              {
                  Title = _contribution.Title
              }

答案 1 :(得分:0)

如果要在SPList中使用DataTable,请尝试以下操作:

           SPList  cList = spWeb.Lists.TryGetList("Customer");
           SPList   oList = spWeb.Lists.TryGetList("Order");


            DataTable cTable= cList.Items.GetDataTable();
            DataTable oTable= oList.Items.GetDataTable();

            var coList = from tbl1 in cTable.AsEnumerable()
                         join tbl2 in oTable.AsEnumerable() on tbl1["Title"] equals           tbl2["CustomerName"]
                         select new
                         {
                             ItemName = tbl2["Title"],
                             CustomerName = tbl1["Title"],
                             Mobile = tbl1["MobileNo"]

                         };
相关问题