(If the title isn't representative for this question please say so, I couldn't come up with a good short description)
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.
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:
WHERE (Application like '%User%' AND Host not like '%fjzhykjety%') OR (REMOTE_HOST like '%uykirlyy%' AND REMOTE_PORT not like '%55555%')
Application, Host and REMOTE_HOST are strings, REMOTE_PORT is a nullable int. I also have a GUID that has to be searchable.
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:
{
"group": {
"operator": "OR",
"rules": [
{
"group": {
"operator": "AND",
"rules": [
{
"condition": "=",
"field": {
"name": "Application",
"type": "select"
},
"data": "User"
},
{
"condition": "<>",
"field": {
"name": "Host",
"type": "text"
},
"data": "fjzhykjety"
}
]
}
},
{
"group": {
"operator": "AND",
"rules": [
{
"condition": "=",
"field": {
"name": "REMOTE_HOST",
"type": "text"
},
"data": "uykirlyy"
},
{
"condition": "<>",
"field": {
"name": "REMOTE_PORT",
"type": "number"
},
"data": 55555
}
]
}
}
]
}
}
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.
What is the best way to implement this advanced search?