我希望用户提交的值作为 SOUNDEX 值到达 MS SQL DB。 例如。 soundex(失忆症)= A520
我的 dbcontext 中有这个函数:
[DbFunction(name: "SOUNDEX", IsBuiltIn = true, IsNullable = false)]
public string Soundex(string query )
{
throw new NotImplementedException();
}
如果我执行 GET 但我想 POST,则效果很好。
在我的控制器中,我们有:-
public async Task<ActionResult<NameRequest>> PostName(NameRequest name)
{
name.Sndx = _context.Soundex(place.Title); //something like this
await _context.SaveChangesAsync();
return CreatedAtAction("GetPlace", new { id = place.Id }, place);
}
要使用 .NET Core Web API 将用户输入值转换为 SOUNDEX 值,您需要在代码中实现
Soundex
方法。以下是如何做到这一点的示例:
[DbFunction(name: "SOUNDEX", IsBuiltIn = true, IsNullable = false)]
public static string Soundex(string query)
{
throw new NotImplementedException();
}
public async Task<ActionResult<NameRequest>> PostName(NameRequest name)
{
name.Sndx = Soundex(name.Title);
await _context.SaveChangesAsync();
return CreatedAtAction("GetPlace", new { id = name.Id }, name);
}