简体   繁体   中英

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. 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

Exception of type 'System.Exception' was thrown

Which is the right way to use db's custom functions in entity framework core 2.0 and UWP 10?

You need to call your function inside linq query like:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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