Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Call CosmosDB ToString method in LINQ

I have a LINQ query where I need to use the CosmosDB ToString method within a query that is built via LINQ in C#. However I have not been able to figure out how to do this. Simply calling ToString() in the C# LINQ expression on the entity value does not work.

I am trying to do a "contains" search on a number value. I can not change the type, and nor can I add a duplicated field that has the number converted to a string.

Essentially what I need is this (in the where clause):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

CONTAINS(ToString(root["MyProperty"]), "MySearchValue")

My current LINQ query is this (MyProperty is of type long):

query.Where(x => x.MyProperty.ToString().Contains("MySearchValue"))

But this generates the following SQL:

CONTAINS(root["MyProperty"], "MySearchValue")

Which does not work since MyProperty is a number, so the Contains method always returns false.

So my question is this: How do I modify my LINQ query to wrap the number value in the ToString() method like in my first code sample above? Or is this even possible currently?

>Solution :

There is actually a bugfix for this issue awaiting merge here: https://github.com/Azure/azure-cosmos-dotnet-v3/pull/3385 Does this apply to your specific situation?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading