title: Querying dynamic in asp.NET with SQL server
body: <p>(If the title isn't representative for this question please say so, I couldn't come up with a good short description)</p>
  
  <p>I'm trying to implement an advanced search function for my web application. This search has to be able to search on a lot of possible combinations. 
  <a href="https://i.stack.imgur.com/My6MD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/My6MD.png" alt="enter image description here"></a></p>
  
  <p>Like shown in the picture every group (AND or OR) can have another group or conditions that can be equal or not equal. The picture should result in a where clause that look like this:</p>
  
  <pre><code>WHERE (Application like '%User%' AND Host not like '%fjzhykjety%') OR (REMOTE_HOST like '%uykirlyy%' AND REMOTE_PORT not like '%55555%')
  </code></pre>
  
  <p>Application, Host and REMOTE_HOST are strings, REMOTE_PORT is a nullable int. I also have a GUID that has to be searchable.</p>
  
  <p>At the moment this frontend search is written in angular and gives me following json (the json depends on the nested groups and conditions) for the example:</p>
  
  <pre><code>{
      "group": {
          "operator": "OR",
          "rules": [
              {
                  "group": {
                      "operator": "AND",
                      "rules": [
                          {
                              "condition": "=",
                              "field": {
                                  "name": "Application",
                                  "type": "select"
                              },
                              "data": "User"
                          },
                          {
                              "condition": "&lt;&gt;",
                              "field": {
                                  "name": "Host",
                                  "type": "text"
                              },
                              "data": "fjzhykjety"
                          }
                      ]
                  }
              },
              {
                  "group": {
                      "operator": "AND",
                      "rules": [
                          {
                              "condition": "=",
                              "field": {
                                  "name": "REMOTE_HOST",
                                  "type": "text"
                              },
                              "data": "uykirlyy"
                          },
                          {
                              "condition": "&lt;&gt;",
                              "field": {
                                  "name": "REMOTE_PORT",
                                  "type": "number"
                              },
                              "data": 55555
                          }
                      ]
                  }
              }
          ]
      }
  }
  </code></pre>
  
  <p>I need a way to sent this data to my .NET application (using a REST API) and query it in the database. I looked into dynamic linq for making the query but because the format of the json file isn't always the same it's hard to make a class in C# for it and build a dynamic linq query for this search.</p>
  
  <p>What is the best way to implement this advanced search?</p>