Set Parameters for Queries in C
If a Query has been configured to use Parameters then your C# code can set these parameters before running the query.
todoc - explain how it's configured to use parameters
In a Razor or WebApi file, you would write something like this:
var allPosts = App.GetQuery("AllBlogPosts");
allPosts.Params("Category", "Web");
var posts = allPosts["Default"];
var dynPosts = AsList(posts);
Warning
Query objects are single use - which is an internal optimization for reliable, rapid access.
So if you retrieve various streams, the query still only executes once.
But if you set a parameter after running the query, you will get an error, unless you call get a new query first.
See the next example:Reset()
var query = App.GetQuery("AllBlogPosts");
query.Params("Category", "Web");
var webPosts = AsList(query);
// this would result in an error
// allPosts.Params("Category", "IT");
// this works - get a new query
query = App.GetQuery("AllBlogPosts");
query.Params("Category", "IT");
var itPosts = AsList(query);
History
- Params was introduced in 2sxc 10.22
Reset()was removed in v21