locked
Using the PreprocessQuery method in a Local Query RRS feed

  • Question

  • I've a master/detail relationship like the one shown in the picture below

    I need to filter the data shown in the OrderHeaders table so I've edited the local query (by clicking the Edit Query link in the screen) but part of the filter is based on a Computed Property so I need to use the PreprocessQuery method because the Computed Properties doesn't appear in the query's "Filter" section.

    But now I've a problem, in the local query the "Write Code" ComboBox is not available like in a Global Query like is shown in the picture below

    So I don't know how to create the PreprocessQuery method in the local query.

    Can someone tell me how to create it?

    If it's not available for local queries is there another way to filter by a Computed Property?

    Thursday, September 5, 2013 12:47 PM

All replies


  • If it's not available for local queries is there another way to filter by a Computed Property?

    I'm not sure if it is or isn't available for local queries, but it seems simplest to me to create a new standard query directly from your table and code your _preProcessQuery in the usual way for the computed property, then add that query to this screen.
    Thursday, September 5, 2013 2:35 PM
  • Hi Allen,

    Thanks for your quick response.

    I agree 100% with you but what I don't know is how to replace the original query (generated by Lightswitch) with the query created by me.

    In the picture below you can see the real tables I'm using in my app

    I can replace the generated query for the first table "PresupuestoAnualsSet" by selecting it and changing the "Query Source" property in the Properties window so I can choose the new standard query created directly from my table as shown in the picture below

    But I'm unable to replace the query that's used by the second table "PresupuestoElementosGastosCollection" because when I select it the "Query Source" doesn't appear in the Properties Window.

    So that's what I'm asking from the beginning...

    How I can replace the query for "PresupuestoElementosGastosCollection" if the "Query Source" property isn't available in the Properties window?

    Thursday, September 5, 2013 3:00 PM
  • I believe those are all entity sets, which you designated to appear on the screen when you created the Details screen information (fig 1).  I'm recommending going back to the original table you want to create a Query from and entering your preProcessQuery code (fig 2).  Then add the newly created Query to the screen with Add Data Item (fig 3).  The Query appears in your View Model (fig 4) and can be selected as a Query Source in the Properties window (fig 5).

    Thursday, September 5, 2013 3:45 PM
  • I've followed the steps as you suggest and now I've the query in the designer as shown in the picture below

    But now I need to bind "PresupuestoElementosGastosConDisponible" query with the table "PresupuestoAnualsSet" table because "PresupuestoAnaualsSet" is binded to the "PresupuestoElementosGastosCollection" query (as shown in the picture).

    How I can do that?

    Thursday, September 5, 2013 4:30 PM
  • I don't believe you'll need to do that.  I believe you can have Presup..Collection on your View and still select Presup...ConDisponible as its Query Source.
    Thursday, September 5, 2013 5:52 PM
  • I can't do that. That's why I asked the question.

    The Query Source is available only for the Master table the Detail table doesn't have Query Source in the Properties window.

    So please check that when you have a chance and let me know if is happening the same to you.

    Thanks for your time.

    Thursday, September 5, 2013 6:20 PM