简体   繁体   English

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

[英]Entity framework core 2.0 Functions how to work

I'm trying to use entity framework core 2.0 functionality (custom functions db) in dbcontext. 我正在尝试在dbcontext中使用实体框架核心2.0功能(自定义函数db)。 I created the next method: 我创建了下一个方法:

    [DbFunction]
    public static int fnGetZona(double latitudine,double longitudine) { throw new System.Exception(); }

If I call this method in my code dbcontext.fnGetZona(latitudine,longitudine) I get 如果我在代码dbcontext.fnGetZona(latitudine,longitudine)调用此方法, dbcontext.fnGetZona(latitudine,longitudine)得到

Exception of type 'System.Exception' was thrown 引发了类型为“ System.Exception”的异常

Which is the right way to use db's custom functions in entity framework core 2.0 and UWP 10? 在实体框架核心2.0和UWP 10中使用db的自定义函数的正确方法是什么?

You need to call your function inside linq query like: 您需要像下面这样在linq查询中调用函数:

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

Also you are missing formal arguments for DbFunctionAttribute . 另外,您缺少DbFunctionAttribute形式参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM