dotnetnuke2sxc

How can I use queries in 2sxc typedcode


So I am trying to use the fancy new TypedCode stuff in 2sxc 18. But I want to get some data from a query. So where I first did something like:

      var query = App.Query["EventDetailsByIds"];
      query.Params("eventid",contactFormRequest["eventid"].ToString() );
      query.Params("dateid",contactFormRequest["dateid"].ToString() );
      var eventobject = AsList(query["EventInfo"]).First();
      var dateobject = AsList(query["DateInfo"]).First();

This will now give an error in 2sxc 18. How can I call a query and add parameters to my call?


Solution

  • There are docs and example (Tutorials) that show this. There is a new method, .GetQuery() and it works in the strongly typed toolchain. The simplest example, assuming your Query returns fields that match an existing Content Type would be:

    // Get all the products from a query (specific stream)
    var myParams = new { CateogryId = catId };
    var prodsInCategory = AsList<Product>(App
      .GetQuery("CategoryDetails", parameters: myParams)
        .GetStream("Products")
    );
    

    So as you can see, the AsList<Product>() is converting your Typed result to StronglyTyped.

    Here is an additional example of GetQuery() using Params in the latest tutorials, scroll down to the last example.
    https://2sxc.org/dnn-tutorials/en/razor/tut/datasources-use