Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Using Linq To SharePoint To Join Multiple Lists

$
0
0

Hello everyone,

I had create a customised site based on SharePoint 2007 and used CAML to perform lots of queries to various lists.

Now we're moving to SharePoint 2013 so this site is required to be recoded for SP2013. While doing this, I wonder if I can make use of SharePoint To Linq to replace all the CAML queries. I was hoping that with Linq, I can now perform queries that joins multiple lists to produce the result in one go. However, there seems to be a problem with this. Below is the test code I've created inside a Windows Form project:

        private void btnGetTopicTree_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            txtResult.Clear();

            // Get the SharePoint list
            EntityList<MasterTopicItem> masterTopic = rssData.GetList<MasterTopicItem>("MasterTopic");
            EntityList<CategoryItem> category = rssData.GetList<CategoryItem>("Category");
            EntityList<TopicItem> topic = rssData.GetList<TopicItem>("Topic");

            // Query for topics
            var topics = from mt in masterTopic
                         join cat in category on mt.RefID equals cat.MasterTopicRefID
                         join t in topic on cat.RefID equals t.CategoryRefID
                         orderby mt.Title, cat.Title, t.Title
                         select new {MasterTopic = mt.Title, Category = cat.Title, Topic = t.Title};

            foreach (var tp in topics)
            {
                txtResult.Text += tp.MasterTopic + "\t" + tp.Category + "\t" + tp.Topic + Environment.NewLine;
            }

            this.Cursor = Cursors.Default;
        }

But as soon as execution hits the "foreach" line, I got an InvalidOperationException, and the message:
The query uses unsupported elements, such as references to more than one list, or the projection of a complete entity by using EntityRef/EntitySet.

So is Linq really only better than CAML in terms of readability? Without the capability of properly joining lists to provide required result I don't see much use of it. Or is it just me missing something?

Any suggestion is very much appreciated.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>