[]
        
(Showing Draft Content)

C1.DataEngine.QueryFactory.CreateQueryFromJsonString

CreateQueryFromJsonString Method

CreateQueryFromJsonString(Workspace, string)

Creates a C1DataEngine query from a JSON string.

Declaration
public static object CreateQueryFromJsonString(Workspace workspace, string json)
Parameters
Type Name Description
Workspace workspace

The C1DataEngine Workspace object in which the query will be created.

string json

The JSON string that describes query elements such as tables, columns, and range conditions.

Returns
Type Description
object

A dynamic object representing the query. The caller is responsible for executing it.

Remarks

Typically, queries are created in C# code using anonymous objects, as in the following example:

dynamic products = workspace.table("Products");
dynamic query = workspace.query("ProductsByColor", new {
    products.ProductColor,
    Count = Op.Count(products.ProductID),
    _range = products.ProductPrice.Gte(100)
});
query.Query.Execute();

Applications that allow end users to create ad-hoc queries can use this method to create a query from a JSON string:

string json = @"{
  "name": "ProductsByColor",
  "tables": [
    "Products"
  ],
  "columns": [
    { "names": [ "ProductColor" ] },
    {
      "names": [ "ProductID" ],
      "op": "Count",
      "alias": "Count"
    }
  ],
  "range": [
    { "name": "ProductPrice",
      "expr": [
        { "op": "Gte", "value": "100" }
      ]
    }
  ]
}";
dynamic query = CreateQueryFromJsonString(workspace, json);
query.Query.Execute();