Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MahdiKarimipour/108452d2584229a54b66ca46d48da0a1 to your computer and use it in GitHub Desktop.
Save MahdiKarimipour/108452d2584229a54b66ca46d48da0a1 to your computer and use it in GitHub Desktop.
How to Run Full-Text Queries using C# and Entity Framework
public IQueryable<Address> GetFullText(
Expression<Func<Address, string>> predicate,
string query,
int currentPage = 0,
int pageSize = 0)
{
if (pageSize == 0)
{
return Context.Addresses
.Where(e => EF.Functions.Contains(e.FullAddress, $"\"{query}\""));
}
return Context.Addresses
.Where(e => EF.Functions.Contains(e.FullAddress, $"\"{query}\""))
.Skip((currentPage - 1) * pageSize)
.Take(pageSize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment