I’ve come across an issue where my cache keys contain a square bracket, and I want to match keys using the OrmLiteCacheClient created using the SqlServerDialect.Provider.
An example key I have is:
urn:ServiceStack.QueryResponse
1[JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main]:PartNoStartsWith=117`
In my code, I’m trying to match using this:
var keys = Cache.GetKeysStartingWith(@"urn:ServiceStack.QueryResponse`1\[JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]").ToList();
But that yields no keys.
In observing the SQL being issued using SQL Profiler, I see this:
exec sp_executesql N'SELECT "Id", "Data", "ExpiryDate", "CreatedDate", "ModifiedDate" FROM "CacheEntry" WHERE "Id" LIKE @0',N'@0 varchar(8000)',@0='urn:ServiceStack.QueryResponse`1\JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]:%'
But this will return 0 rows because the ESCAPE clause needs to be provided - so for instance this query returns the correct results:
SELECT * FROM CacheEntry WHERE Id LIKE 'urn:ServiceStack.QueryResponse`1\[JiwaFinancials.Jiwa.JiwaServiceModel.Tables.IN_Main\]:%' ESCAPE '\'
Is there a way to cause the OrmLiteCacheClient to correctly escape the query text?
EDIT: Escaping the \ correctly