locked
Lightswitch, LINQ and RIA question RRS feed

  • Question

  • I've created a LINQ query in LinqPad that returns an IOrderedQueryable object with two EnumerableQuery objects.

    This LINQ query provides all of the data required to run 9 different processes where each process requires the data to be ordered differently.

    The results of the LINQ query would NOT be displayed in LightSwitch; results would only be used in a process.

    Questions:

    1) It appears that there is no way inside of native Lightswitch to execute a LINQ query where one tries to return specific fields via the Select/Projection. (ie: not returning an entity) Is this true?

    2) Assuming #1 is true, could RIA be called from either a client side screen and/or from server side Entity_Updating code?

    3) I could execute 3 LINQ queries that returned entity sets that would contain the necessary information. However, I would still have the challenge with the order of the data. How can one convert the result sets from a LINQ query into a local LINQ query so the remote LINQ query is executed once and then the local LINQ query can be re-queried with different order bys?

    Any thoughts would be great!


    Thank you, Bill

    Thursday, September 6, 2012 7:39 PM

Answers

  • 1) It appears that there is no way inside of native Lightswitch to execute a LINQ query where one tries to return specific fields via the Select/Projection. (ie: not returning an entity) Is this true?

    2) Assuming #1 is true, could RIA be called from either a client side screen and/or from server side Entity_Updating code?

    3) I could execute 3 LINQ queries that returned entity sets that would contain the necessary information. However, I would still have the challenge with the order of the data. How can one convert the result sets from a LINQ query into a local LINQ query so the remote LINQ query is executed once and then the local LINQ query can be re-queried with different order bys?

    1) Correct, if you want to use the returned entities in data binding. If you want to shape your entities you have to use either a RIA domain service or add database views and import those into LS. Digest views work great for just populating grids while using the real full entities for editing. RIA domain services are the most powerful of course as you can do anything. You could also use a combination of one data source attached directly to the database and another just for creating shaped/projected entities.

    2) When a RIA domain source is imported into LS you can call it from the client or the server side as it behaves just like a standard database attached or intrinsic datasource

    3) Sort of depends on 1 and 2 above and where you go with the overall solution. For special filtering and ordering nothing beats a RIA domain service query IMHO. You can add parameters that take search terms, filter criteria and even order by criteria and process it all server side and only have the result come down the wire. LINQ inside LS is powerful as well of course and you have a lot of control with that IQueryable interface, but ultimately it depends how complex your requirements are.

    I'm a big fan of RAI domain services in LS and not sure I will ever create a LS solution that does not utilise that in one way or another.

    How the above gives you some additional information.

    Regards


    Xander

    • Marked as answer by jessiedog Friday, September 7, 2012 12:29 PM
    Friday, September 7, 2012 2:50 AM

All replies

  • Hi Bill

    Hope the below article may help you

    How Do I: Display a chart built on aggregated data

    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.

    Thursday, September 6, 2012 7:51 PM
  • Rashmi,

    Thank you for the reply; I've previously read that article but it was published in 2011 so I wanted to confirm the select/project aspect as it relates to 2012.


    Thank you, Bill

    Thursday, September 6, 2012 8:21 PM
  • Hi Bill

    It is applicable for Visual Studio 2012 Lightswitch. You can use it. To display chart you need to install Silverlight 5 toolkit.

    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.

    Thursday, September 6, 2012 8:50 PM
  • Rashmi,

    Sorry, I've not been clear. I am 100% confident that RIA would solve the challenge.

    I am trying to figure out if there is a way to accomplish the task without RIA.

    If RIA must be used, can the code be called from the client and server. I know it can be called from the client but can it be called from Entity_Updating.


    Thank you, Bill


    • Edited by jessiedog Thursday, September 6, 2012 10:31 PM
    Thursday, September 6, 2012 10:30 PM
  • 1) It appears that there is no way inside of native Lightswitch to execute a LINQ query where one tries to return specific fields via the Select/Projection. (ie: not returning an entity) Is this true?

    2) Assuming #1 is true, could RIA be called from either a client side screen and/or from server side Entity_Updating code?

    3) I could execute 3 LINQ queries that returned entity sets that would contain the necessary information. However, I would still have the challenge with the order of the data. How can one convert the result sets from a LINQ query into a local LINQ query so the remote LINQ query is executed once and then the local LINQ query can be re-queried with different order bys?

    1) Correct, if you want to use the returned entities in data binding. If you want to shape your entities you have to use either a RIA domain service or add database views and import those into LS. Digest views work great for just populating grids while using the real full entities for editing. RIA domain services are the most powerful of course as you can do anything. You could also use a combination of one data source attached directly to the database and another just for creating shaped/projected entities.

    2) When a RIA domain source is imported into LS you can call it from the client or the server side as it behaves just like a standard database attached or intrinsic datasource

    3) Sort of depends on 1 and 2 above and where you go with the overall solution. For special filtering and ordering nothing beats a RIA domain service query IMHO. You can add parameters that take search terms, filter criteria and even order by criteria and process it all server side and only have the result come down the wire. LINQ inside LS is powerful as well of course and you have a lot of control with that IQueryable interface, but ultimately it depends how complex your requirements are.

    I'm a big fan of RAI domain services in LS and not sure I will ever create a LS solution that does not utilise that in one way or another.

    How the above gives you some additional information.

    Regards


    Xander

    • Marked as answer by jessiedog Friday, September 7, 2012 12:29 PM
    Friday, September 7, 2012 2:50 AM