gpt4 book ai didi

c# - 从Entity Framework Core调用 native SQL Server函数

转载 作者:太空狗 更新时间:2023-10-29 23:49:34 27 4
gpt4 key购买 nike

实体框架6使用a way来注册具有[dbfunction]属性或SQLFunctions类的SQL Server内置函数。最初,据我所知,EF核心没有这种能力;但似乎从here看来,它现在通过EF.Functions存在。但是,我找不到任何地方来描述如何使用它。我是否用属性和代码回退来装饰实现?我在代码中调用函数吗?具体来说,我想调用sql serverSOUNDEX()函数,但我确信还有很多其他的例子。

最佳答案

可以在dbcontext中编写函数定义

[DbFunction("SOUNDEX", "")]
public string SOUNDEX(string str) => throw new NotSupportedException();

如果要在ef core中调用此方法,请尝试以下代码:
var db=new MyDbContext();
var result= db.SOUNDEX("Persepolis");

关于c# - 从Entity Framework Core调用 native SQL Server函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43701551/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com