0

What is wrong with this code ?

var tags = "Tom;DC;Harry"
var tagArray = tags.Split(';');
var searchTags = dbContext.Tags.Where(t => t.Active && tagArray.Contains(t.TagLabel, StringComparer.OrdinalIgnoreCase)).ToList();

This gives me the following error at runtime.

LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Collections.Generic.IEnumerable1[System.String], System.String, System.Collections.Generic.IEqualityComparer1[System.String])' method, and this method cannot be translated into a store expression.

But when I turn the code to:

var searchTags = dbContext.Tags.Where(t => t.Active && tagArray.Contains(t.TagLabel.ToLower())).ToList();

It works for me, but this way I have to convert all tags & tagArray to lower. Is there any way around to ignorecase in EF query ?

user449689
  • 3,142
  • 4
  • 19
  • 37

0 Answers0