0
  1. I Want to create query with Visual Query designer and included sort, filter, caching and multiple strams. Basicly complex query.

  2. I know that I can parametrize values with QueryString value or In-Value Provider or can be "hardcoded" in query.

  3. But my question is how to change one or more of this values from razor code

eg: If I load existing query like this:

var q = App.Query["query-name];

I get results for this query. But in this query there is a "hardcoded" value eg:"finished" for some Filter, my question is:

Is posible to reuse this query as template and then in razor code change this hardcoded value. Something like using QueryString or In-Value token, but this values comes from some other logic in razor script.

Jernej Pirc
  • 504
  • 1
  • 4
  • 13

1 Answers1

1

This is a good question which nobody asked so far :)

Let's just look at some basics: the value provider used for the queries is a special dictionary containing value-provider objects. It is created when it's accessed, and can be modified as you wish, until you access a query - which then uses the properties contained.

So yes: you can either change existing parameters (like change what QueryString:Id would deliver) or you could also add your own parameter lists, like CodeParams:Size.

To get a good feeling on how to do this, please check https://github.com/2sic/2sxc/blob/master/SexyContent/DataSources/ConfigurationProvider.cs which builds a configuration provider. This is what always runs before your query.

You should be able to access and modify the dictionary by

  1. Create an own app object
  2. Create an own configuration object
  3. InitData of the app using the own configuration object
  4. Accessing the query

It feels a bit complex, but it's fairly simple. Best check the app-factory to get a feel of the code: https://github.com/2sic/2sxc/blob/3602461f3c4154857d84c7f6ad1a3d1e96b78ba3/Environment/Dnn7/Factory.cs

Option 2: Note that there is also another way: You could get the query, and modify it so it doesn't use parameters, but the value you just supplied. This may feel a bit messy, but it's all very clear what happens. Basically the system is a chaining of data-source items, usually connecting a sources Out["Default"] to the In["Default"]. Each data-source has a different type and different properties.

You can therefor get a query data-source, navigate along the object to the right data-source object, cast it to the right type and then change the filter/parameter property to whatever you need. this will probably take quite some fiddling around though, so I wouldn't recommend it :).

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21