SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I merge two lists when using REST services? You can't use union with linq and dataservicequery so I'm not sure where to go.

The following doesn't work with dataservicequery...

var docQuery = (from docs in context.Documents.AsQueryable()
                        select new DocsColumns()
                            Title = docs.Title
                            //     Element = docs.Elements.Title 
                        .Union(from rules in context.Rules.AsQueryable()
                               select new DocsColumns()
                                   Title = rules.Title
                                   //    Element = rules.Elements.Title 

                               as DataServiceQuery<DocsColumns>;

This link doesn't help much either....

Any ideas? Really struggling on this one.

share|improve this question

Using Linq, You can merge using below pseudo code :

using (DataContext context = new DataContext("<<Site Url>>"))

    EntityList<Item> allDocuments = context.GetList<Item>("Documents");
    EntityList<Item> allRules = context.GetList<Item>("Rules");

    List<Item> allDocumentItems = <<Select relevant docs from allDocuments>>;    
    List<Item> allRuleItems = <<Select relevant rules from allRules>>;

    IEnumerable<Item> mergedItems = allDocumentItems.Union(allRuleItems);

Note that Your source code must provide a declaration of an Item class, and that class must declare properties for each of the columns in the content type that your queries reference. For e.g.:

[ContentType(Name="Item", Id="0x01")]
public partial class Item
    [Column(Name = "Title", FieldType = "Text")] 
    public String Title { get; set; }
share|improve this answer
I'm using the client-side of things so Linq-to-Sharepoint won't work. – CeeMoney Nov 3 '11 at 22:26
Doesn't really matter. If you want to union stuff using Linq, you first need to retrieve everything you want to union in the first place. Where that data comes from doesn't matter to linq, at least not when you've already got the data in lists. So query both of your REST sources, map the data to lists of the same class type and union those. – Jasper Apr 1 '12 at 9:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.