How I can add Or instead of And in custom QueryableExtension Npgsql text[]? If its possible?

64 Views Asked by At

I need help with queryableExtension for Npgsql string array.

I have column in database as type Text[]. This contains multiple values and I want to search in them but not with AND but with OR.

I have query extension which work fine, search in whole string array, but with all are equals.

public static IQueryable<T> ContainsOfStringArray<T>(this IQueryable<T> source,
    PropertyInfo property, string[] values)
{
     source = source.Where(_ => values.All(v => EF.Property<string[]>(_, property.Name).Contains(v)));

     return source;
}

I have data

record 1 - string[] { AAA, BBB }
record 2 - string[] { AAA }

If I pass one parameter AAA then return 2 records. If BBB return 1 record.

BUT if I pass two parameters AAA,BBB then return 0 records.

My question is "How I can add Or instead of And? If its possible".

I tried wrote custom Expression.Call but without success. I don't know how call Contains function from Npgsql for right translate because string[] does not contain Contains function :(

If you have any idea how to write Expression.Call for predicate this would be excellent.

Using Asp.Net Core 3.1

Ty so much for help




--- EDIT CLOSED----

Change All() to Any() do right work. Thanks to @IvanStoev comment

0

There are 0 best solutions below