Skip to content
Advertisement

How to map from query string to SQL query? [closed]

So I have as search endpoint

that returns a list of users from the cosmosDb based on email, name etc.

The problem is that I don’t know how to convert the query string into an SQL query or LINQ statement. I have googled for hours, but I can’t find any examples, but it just seems weird if I have to write my own query parser?

Advertisement

Answer

Given the example value of query in your comment, I guess you actually mean something like /users/search?query=firstname%3DLucy%26lastname%3DJohnson (note the %3D instead of %D and %26 instead of &). The decoded value of this would be firstname=Lucy&lastname=Johnson. In this case you’d have kind of a query string inside the value of your query string’s query parameter.

One solution would be to get rid of the query parameter and just use the parameters of your actual query as normal query string parameters.

For example:

With the solution described above, you don’t have to parse anything as the values of your query would be parsed out of the box by asp.net. You would however have to put together the query to the database yourself.

If you want to stick to your original design and have one single query parameter that itself is a query string you can do the following:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement