locked
Is it possible to use group by in LightSwitch? RRS feed

  • Question

  • I have tried to add a group by to the PreprocessQuery and but it doesn't seem to like it. This is my query:

    partial void FilterAndSortMyEntityByUser_PreprocessQuery(ref IQueryable<MyEntity> query)
            {
                query = query.Where(m => m.aspnet_User.LoweredUserName == _currentUser).GroupBy(m => m.aspnet_User.UserName); 
            }

    This throws an exception:

    Error 2 Cannot implicitly convert type 'System.Linq.IQueryable<System.Linq.IGrouping<string,LightSwitchApplication.MyEntity>>' to 'System.Linq.IQueryable<LightSwitchApplication.MyEntity>'. An explicit conversion exists (are you missing a cast?)

    Tried casting it but still did NOT work!! Any help will be very much appreciated.


    • Edited by BigBee Tuesday, March 18, 2014 11:45 PM
    Tuesday, March 18, 2014 11:42 PM

Answers

  • Hi

    Preprocessquery does not support groupby in lightswitch. If you want to shape your data then you have to use WCF RIA Service. Please take a look at the below post.

    How Do I: Display a chart built on aggregated data (Eric Erhardt)

    HTH

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.

    • Marked as answer by BigBee Friday, March 21, 2014 6:32 AM
    Wednesday, March 19, 2014 2:04 AM

All replies

  • Hi

    Preprocessquery does not support groupby in lightswitch. If you want to shape your data then you have to use WCF RIA Service. Please take a look at the below post.

    How Do I: Display a chart built on aggregated data (Eric Erhardt)

    HTH

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.

    • Marked as answer by BigBee Friday, March 21, 2014 6:32 AM
    Wednesday, March 19, 2014 2:04 AM
  • How come grouping doesn't come out of the box in LS?
    Friday, March 21, 2014 6:33 AM
  • You can also create a view in SQL Server to do the GROUP BY and then add the view to your app as an external data source.
    Friday, March 21, 2014 5:05 PM
  • Grouping works fine in LS code, but not in a PreprocessQuery event. The query has to return the expected entity type and a group becomes a different object type.

    Paul

    Friday, March 21, 2014 7:47 PM