locked
How to select desired columns or entity properties in lightswitch query? RRS feed

  • Question

  • Hi

    I need to select only desired columns from the table or entity in light switch. Every example I see they are selecting the whole collection. For example I have suburbs table which has State, Suburb and Pincode. I want to write query at  PreprocessQuery method.

     

    partialvoidGetSuburbsByState_PreprocessQuery(stringState, refIQueryable<Suburbs> query)

            {

        query =

    fromdata inquery wheredata.State==State selectdata;

      

    // query = from data in query where data.State == State select data.Suburb;


            }

    But instead of selection all columns I want to select desired only. Here I want to select only Suburb from list. But it is not allowing. How can I do this  in Lightswitch??

    }

    Monday, December 28, 2015 4:46 AM

Answers

  • Hi sandeepkothapalli,

    Could you tell us where do you want to us the selected Suburb columns?

    As far as I know, in PreprocessQuert method, it will return entity collection, which is the default result, we could not change it for this method.

    If you just want to show the assign Suburb on screen, please edit on screen. For example, the query returns a list of Suburs, but you just want show the Subur column. Then you can delete other columns on screen.

    If misunderstanding, please feel free to let me know.

    Best Regards,
    Weiwei

    • Proposed as answer by Otis Ranger Tuesday, January 5, 2016 11:31 AM
    • Marked as answer by Angie Xu Thursday, January 7, 2016 1:56 AM
    Tuesday, December 29, 2015 1:59 AM
    Moderator
  • To change the shape of the data you need to use a RIA Service or a SQL Server view.  Otherwise you can only retrieve a collection containing all columns of the lightswitch entity.  You can't change the shape of the data in the PreprocessQuery method.
    • Edited by Hessc Tuesday, December 29, 2015 2:14 AM
    • Proposed as answer by Otis Ranger Tuesday, January 5, 2016 11:31 AM
    • Marked as answer by Angie Xu Thursday, January 7, 2016 1:57 AM
    Tuesday, December 29, 2015 2:12 AM

All replies

  • Hi sandeepkothapalli,

    Could you tell us where do you want to us the selected Suburb columns?

    As far as I know, in PreprocessQuert method, it will return entity collection, which is the default result, we could not change it for this method.

    If you just want to show the assign Suburb on screen, please edit on screen. For example, the query returns a list of Suburs, but you just want show the Subur column. Then you can delete other columns on screen.

    If misunderstanding, please feel free to let me know.

    Best Regards,
    Weiwei

    • Proposed as answer by Otis Ranger Tuesday, January 5, 2016 11:31 AM
    • Marked as answer by Angie Xu Thursday, January 7, 2016 1:56 AM
    Tuesday, December 29, 2015 1:59 AM
    Moderator
  • To change the shape of the data you need to use a RIA Service or a SQL Server view.  Otherwise you can only retrieve a collection containing all columns of the lightswitch entity.  You can't change the shape of the data in the PreprocessQuery method.
    • Edited by Hessc Tuesday, December 29, 2015 2:14 AM
    • Proposed as answer by Otis Ranger Tuesday, January 5, 2016 11:31 AM
    • Marked as answer by Angie Xu Thursday, January 7, 2016 1:57 AM
    Tuesday, December 29, 2015 2:12 AM