Jasmine Jasmine - 2 months ago 12
C# Question

Search by multiple strings using SQLFunction.Difference with EF

This works great when the input is a single string

In this example "Lorem ipsum"

dbContext.NewsArticles.Where(article => SQLFunction.Difference(article.Text, "Lorem ipsum") == 3).ToArray()


How can I search by multiple strings? In other words, the input is a string[] or List

var input = new List<string>{
"Lorem ipsum dolor",
"elementum lacinia",
"cursus nulla molestie",
}


Is this even possible?

Answer

You should be able to just use that list with Any.

dbContext.NewsArticles
    .Where(article => input.Any(x => SQLFunction.Difference(article.Text, x) == 3))
    .ToArray();
Comments