C# 实体框架核心2.0功能如何工作

C# 实体框架核心2.0功能如何工作,c#,entity-framework,C#,Entity Framework,我试图在dbcontext中使用EntityFramework核心2.0功能(自定义函数db)。 我创建了下一个方法: [DbFunction] public static int fnGetZona(double latitudine,double longitudine) { throw new System.Exception(); } 如果我在我的代码中调用这个方法dbcontext.fnGetZona(latitudine,longitudine) 引发了类型为“Sy

我试图在dbcontext中使用EntityFramework核心2.0功能(自定义函数db)。 我创建了下一个方法:

    [DbFunction]
    public static int fnGetZona(double latitudine,double longitudine) { throw new System.Exception(); }
如果我在我的代码中调用这个方法
dbcontext.fnGetZona(latitudine,longitudine)

引发了类型为“System.Exception”的异常


在entity framework core 2.0和UWP 10中使用db自定义函数的正确方法是什么?

您需要在linq查询中调用您的函数,如:

var test = (from r in context.SomeEntity
where r.Zona == DBContext.fnGetZona(lat, lon)
select r).ToList();

此外,还缺少
DbFunctionAttribute

的形式参数。您需要在linq查询中调用函数,如下所示:

var test = (from r in context.SomeEntity
where r.Zona == DBContext.fnGetZona(lat, lon)
select r).ToList();

另外,您缺少
DbFunctionAttribute

的形式参数。如果您的代码抛出了该错误,请参阅函数体:
throw new System.Exception()我的db自定义函数返回一个int。@dbraillon我猜该函数映射到我的db自定义函数。您能告诉我如何实现它吗?好的,您的代码会抛出该错误,请参阅函数体:
throw new System.Exception()我的db自定义函数返回一个int。@dbraillon我猜该函数映射到我的db自定义函数。您能告诉我如何实现它吗?以及schema-to-annotation方法。将模式转换为注释方法。谢谢