FreeText in Entity Framework Core

551 views Asked by At

I am trying to implement search and I am using entity framework core. I tried using the following query-

var users = await context.Users.Where(u => EF.Functions.FreeText(u.UserName, searchString)).ToListAsync();

This query is throwing the following error -

InvalidOperationException: The 'FreeText' method is not supported because the query has switched to client-evaluation.

Model

public class User
    {
        public int Id { get; set; }
        public string UserName{ get; set; }
    }

Controller

  [HttpGet("search/{searchString}")]
    public async Task<IActionResult> SearchUser(string searchString)
    {
        var users=await repository.Search(searchString);
        return Ok(users);
    }

I even tried switching u.UserName with "UserName" as some answers to similar questions suggested but got the same result. I'd be glad if someone could help me with this.

0

There are 0 answers