SearchExtensions icon indicating copy to clipboard operation
SearchExtensions copied to clipboard

Search by joining properties.

Open kadirgedik opened this issue 2 years ago • 1 comments

What i want to do;

query.Search(x => string.Join(" ", x.Property1, x.Property2)).Containing("searchTerm");

This method does not work well. is there another way?

thanks.

kadirgedik avatar Apr 12 '23 11:04 kadirgedik

Have you tried this?

[...]
query.Select(x => new { JoinedItem = x.Property1 + " " + x.Property2 })
.Search(y => y.JoinedItem).Containing("searchTerm")
[...]

Not sure EF knows about string.Join(), but it's an easy concatenation. There are other ways to do it too, the worst being to actually get the results into memory and using string.Join(). Another way is to have a computed column on that database table, that holds exactly the value you want => Property1 + " " + Property2. Then, you use Search() on this column.

Crusader2010 avatar Nov 21 '23 09:11 Crusader2010