我正在尝试在dbcontext中使用实体框架核心2.0功能(自定义函数db)。 我创建了下一个方法:
[DbFunction]
public static int fnGetZona(double latitudine,double longitudine) { throw new System.Exception(); }
如果我在代码dbcontext.fnGetZona(latitudine,longitudine)
中调用此方法,我会
抛出了'System.Exception'类型的异常
在实体框架核心2.0和UWP 10中使用db的自定义函数的正确方法是什么?
答案 0 :(得分:1)
您需要在linq查询中调用您的函数,如:
var test = (from r in context.SomeEntity
where r.Zona == DBContext.fnGetZona(lat, lon)
select r).ToList();
此外,您还缺少DbFunctionAttribute
的正式参数。