GetItems from Sharepoint using LINQ RRS feed

  • Question

  • Hello, I am creating SL app using SL4 and Sharepoint 2010. I am downloading list items from SP List using Sharepoint Client library for SL. I just want to ask if I got this right.

    If I want to download as small amount of data as possible. So I use lambdas in ClientContext.Load method. But if I try to filter items - with Where method - based on some string that must be contained in some field, exception is raised - something like "The StartsWith/ToString/Equals member cannot be used in the expression".

    So this code throws exception:  

    ClientContext.Load( _listItemCollection, items=>items.Where( item=>item["Title"].ToString().StartsWith("some value") ) );

      So, to create such filter I must use CAML:

    CamlQuery query = new CamlQuery();
    query.ViewXml = "some xml in text, that is definitely more complicated to create than lambdas or linq";

     Well, so my question is: is this right way to filter items from sharepoint? Is there any way to make this work in lamba expressions or linq?

    Because, if I must create XML for CamlQuery I dont really see this Client Object model SOOOO great....

    Thanks for any answer. 

    Tuesday, November 9, 2010 9:17 AM


All replies