HQL instruction "Contains"?

I have an object that has a string property called tags. I would like to request this object based on the fact that a particular row is in the Tags property.

So, for example, I would have the IList function GetEntityByTag (string tag), this will return all Entities that have the tag value in the "Tags" property.

I tried using the ICriteria ... Expression.In (PropertyName, Value) approach, but this is the exact opposite. I need something like Expression.In (Value, PropertyName).

IQuery might be a better strategy, but I could not find any type of HQL status for the CONTAINS 'abc' property.

Any help or a waypoint would be greatly appreciated!

+3
source share
2 answers

Do you mean Expression.Like (PropertyName, Value)?

0
source

If you want to know if a tag is a substring in the Tags property, you can consider the following tips:

  • You might want to convert the string you enter into and look for lowercase first. Expression.ilike does it for you. Score.
  • To find out if your search query is anywhere in the field, you can set the MatchMode parameter in the ilike function in MatchMode.ANYWHERE.

If, as you commented earlier,

let say my property, 'Tags' = a, b; from; d, e. I want to know if 'a' exists in tags. Will Expression.Like ("Tags", "a") be true?

'a; b; c; d; e' - , Expression.ilike( "", "a", MatchMode.ANYWHERE) true.

+3

Source: https://habr.com/ru/post/1702886/


All Articles