locked
SkipWhile - The query operator 'SkipWhile' is not supported. RRS feed

  • Question

  •  

    Dear NG,

     

    I'm using AdventureWorks-Database in my example.

     

    I'm trying to execute the following Query Expression

    var qry = (from cr in _db.Currencies select cr).SkipWhile(cr => cr.Name.Length >= 10);

     

    After execution, I'm always getting the error "The query operator 'SkipWhile' is not supported."

     

    What is wrong here?

     

    Best,

    Ozgur Aytekin

     

    Monday, September 24, 2007 7:02 PM

Answers

  • LINQ to SQL does not support translating SkipWhile or TakeWhile as there is no equivalent in SQL.

     

    Monday, September 24, 2007 7:04 PM
  • So far yes.  However, anyone building a LINQ provider or supporting the LINQ operator pattern is free to implement it.

     

    Tuesday, September 25, 2007 8:05 PM

All replies

  • LINQ to SQL does not support translating SkipWhile or TakeWhile as there is no equivalent in SQL.

     

    Monday, September 24, 2007 7:04 PM
  • Is it only supported in LINQ to Objects?

    Monday, September 24, 2007 7:09 PM
  • Is SkipWhile only supported in LINQ to Objects?

    Tuesday, September 25, 2007 7:09 PM
  • So far yes.  However, anyone building a LINQ provider or supporting the LINQ operator pattern is free to implement it.

     

    Tuesday, September 25, 2007 8:05 PM
  • We could actually use:

     

    var qry = (from cr in _db.Currencies select cr).Where(cr => cr.Name.Length < 10); 
    OR
    var qry = from cr in _db.Currencies             
                  where cr.Name.Length < 10
                  select cr; 
     
    Friday, August 15, 2008 1:23 AM
  • With a slight variation, you can achieve what you want (though with added memory overhead):

     

    Code Snippet

    var qry = (from cr in _db.Currencies select cr).ToList().SkipWhile(cr => cr.Name.Length >= 10);

     

     

     

    The call to ToList() will execute the query against the DB, at which point you'll be using Linq to Objects for the call to SkipWhile().  I'm not sure what you're actually trying to accomplish here, though.  I can't see what purpose this query actually serves in the real world.  It may be possible you can accomplish your goal more efficiently by using a different query entirely.
    Friday, August 15, 2008 4:07 PM
  • In my humble opinion, better use the first way (Where rather than ToList) as it will transfer less data from the server, cuz the server will not return all the data as it would do in ToList, but again this is just in my humble opinion.


    Shimmy
    Saturday, February 28, 2009 9:57 PM