Fetch Serialised List of String in EF Core Where Clauses

Viewed 34
public class Post
{
   public string Id { get; set;}
   public string BodyText { get; set;}
   public List<string> HashTags { get; set;}
}

HashTags is set to be serialised in SQL Server and then deserialised to List<string> in .Net Code. I want to fetch the list of posts that contains some keywords in HashTags List like this

var keyword = "ab";
var posts = await _appDbContext.Posts.Where(x => x.HashTags.Contain(keyword));

However, it gives me the exception saying that Cannot translate Contains function and tell me

 Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync()

AsEnumerable() fetch all records and then apply filter in client side .Net Code but it negatively affects the efficiency in performance. Is there any better solution for this problem?

0 Answers
Related