I tried to implement Fuzzy match(Fuzzy Search) so i conclude the use of Soundex in my .Net 6.0 application using EF 5.0.6. I added what is below to my DBContext for me to use the Soundex function
[DbFunction(Name = "SOUNDEX", Schema = "")]
//[DbFunction("SqlServer", "SOUNDEX")]
public static string SoundsLike(string keyword)
{
throw new NotImplementedException();
}
When ever i call this function it see my function as a table and it returns the error
Microsoft.Data.SqlClient.SqlException
HResult=0x80131904
Message=Cannot find either column "dbo" or the user-defined function or aggregate "dbo.SOUNDEX", or the name is ambiguous.
Source=Core Microsoft SqlClient Data Provider
StackTrace:
at UserMS.Controllers.LocalWatchlistController.GetDataTabelData() in C:\Users\techy\OneDrive\Documents\ZenithSanctionProject\UserMS\Controllers\LocalWatchlistController.cs:line 91
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
How can i implement this fuzzy logic to search records in SQL Server database.
On the DB context i added
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
[DbFunction(Name = "SOUNDEX", Schema = "")]
//[DbFunction("SqlServer", "SOUNDEX")]
public static string SoundsLike(string keyword)
{
throw new NotImplementedException();
}
public DbSet<UserProfile> UserProfile { get; set; }
}
My search method method
if (!string.IsNullOrEmpty(searchValue))
{
searchValue = searchValue.ToLower();
_GetGridItem = _GetGridItem.Where(obj => obj.Id.ToString().Contains(searchValue)
obj._EPONUMO_EPONUMIA_.ToLower().Contains(searchValue)
|| ApplicationDbContext.SoundsLike(searchValue) ==
ApplicationDbContext.SoundsLike(obj.full_name)
);
}
I used a data table to display my information on the razor pages.
Any kind of contribution on implementing Soundex or Fuzzy Logic search on Net 5.0 or Net 6.0 will be appreciated.