I have a table Sentences that has an ID and Sentence column. This is a fairly large table, +- 100000 rows. I am given a list of words and I need to find the sentences that contains these words. The resultant sentences must be unique.
_session.All<Sentence>()
.Select(T => new { ID = T.ID, Sentences = T.sentence.Split(' ') })
.Where(S => S.Sentences.Intersect(Words).Count()>0)
.Select(R=>R.ID)
from here it’s pretty simple but this seems inefficient.
Instead of
.Count()>0you should use.Any().Also, it does not appear as though you are doing anything to get unique sentences, like use a
.Distinct()at the end.Maybe like this: