Kraken
Kraken

Reputation: 119

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?

Upvotes: 0

Views: 1010

Answers (1)

Rafal
Rafal

Reputation: 12629

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.

Upvotes: 2

Related Questions