0

I would like to improve the performance of the following LINQ statement to ensure that it's getting back the list as efficiently as possible.

I am receiving the following warning on the server: The LINQ expression 'where [s].Building.Contains(__searchString_0, CurrentCulture)' could not be translated and will be evaluated locally.

  string searchString = siteCode + " " + building + " ";

  var floorLocations = _applicationDbContext.CurrentLocations
                .Where(s => s.Building.Contains(searchString, StringComparison.CurrentCulture)).OrderBy(x => x.Building)
                .Select(s => s.Building.Split('-', StringSplitOptions.None)[0]).Distinct().ToList();

Overall I want to ensure that this LINQ statement is optimized as it will be called multiple times per minute at peak usage throughout the day.

codeg
  • 333
  • 1
  • 6
  • 21
  • I suppose you have Non Clustered Index on Building field ? Also try that https://stackoverflow.com/questions/2369022/using-contains-in-linq-to-sql – Vladimir May 07 '19 at 15:05
  • Yes, Building field is Non Clustered Index. – codeg May 07 '19 at 15:16
  • 1
    If you leave off the `StringComparison` does that get rid of the error? Perhaps it won't delegate the `Contains` to the SQL engine since it can't ensure the culture? – NetMage May 07 '19 at 18:44

0 Answers0