I need a help on to construct dynamic cosmos query using c#. In cosmos database having name like "test.a'lcarte", so in the code we are trying to construct the dynamic query like
string _queryText = "SELECT distinct value c.createdby FROM c where c.createdby in(" + "'test.a\\'lcarte'" + ") and c.isactive!=false";
'test.a'lcarte' can be replace with input as string runtime.
this is output of _queryText :
SELECT distinct value c.createdby FROM c where c.createdby in('test.a'lcarte')
, looks like backslash() with apostrophe escpaing backslash and due to this string is not going correct format.
So my question is how to constrcut string using backslash with apostrophe.
Note :
SELECT distinct value c.createdby FROM c where c.createdby in('test.a\\'lcarte') and c.isactive!=false
, query working fine in cosmos query editor and my intention to pass or construct the same query dynamically in C# code.
To retrieve a name containing special characters from a Cosmos collection, use
\\instead of special characters or by using verbatim string@In the code below, theReplacefunction is used to escape single quotes in the input string by adding a backslash before them or verbatim@before the string.Using backslash
\\:Output:
test.a'lcarteUsing verbatim symbol:
Output:
test.a'lcarte