I have a query in which I pass the search term to filter the list of Companies
, either by Email
or company Title
which is stored in another table (TranslationTexts
) as Text
column for multiple locales.
The query runs fine but it is very heavy and takes time. How can I make it more efficient?
The query:
gm.ListData = context.Companies.ToList()
.Where(a => a.AspNetUser.Email.NullableContains(searchTerm) ||
a.TitleTranslation.TranslationTexts
.Where(b => b.Text.NullableContains(searchTerm)).Any()
).Select(c => new ListCompany
{
CompanyID = c.CompanyID,
EmailID = c.AspNetUser.Email,
Title = c.TitleTranslation.TranslationTexts.FirstOrDefault(d => d.Locale == Locale).Text
}).ToList();