I am using Entity Framework 6 and Oracle Database 11g (ODP.NET Manage Driver).
How to call UTL_MATCH.EDIT_DISTANCE
function in LINQ query?
I am using Entity Framework 6 and Oracle Database 11g (ODP.NET Manage Driver).
How to call UTL_MATCH.EDIT_DISTANCE
function in LINQ query?
There is an awesome Library to help with mapping Database functions and Stored Procedures to Entity Framework.
Install the Nuget package
Create Extension Methods for functions:
Map it on your EntityFramework Context:
Call your newly mapped "ToNumber()" function in your LINQ queries:
And bobs your Uncle.
Unfortunately, for Oracle functions that resides in a different schema, like
UTL_MATCH.EDIT_DISTANCE
it will not work. You are supposed to be able to set the schema, but it seems like it is not currently working with Oracle or something. But for other fucntions likeSOUNDEX
etc. this should work fine.You can read the Documentation for EntityFramework.Functions here
I agree with Gerrie Pretorius and if you used database first model , you must add a function to edmx file like below
Then add a static function to OracleFunctions class like below
After that you can use ToNumber function freely.
There are two ways to achieve this: Call ODP.NET ADO.NET classes directly via a context, or use the Import Function dialog in Entity Designer.
1) Here's some example code showing how you can call procs from EF code without importing them into your model - essentially you are pulling out the OracleCommand object. A little investigation online will help you modify this for the package procedure you actually want to call:
2)
Have a look at the Entity Framework chapter in the Oracle Developer Tools for Visual Studio online help. You use the "Run Stored Procedure" Dialog to do it. It adds the metadata to the config file automatically.
https://apexapps.oracle.com/pls/apex/f?p=44785:24:103660957753593:::24:P24_CONTENT_ID,P24_PROD_SECTION_GRP_ID,P24_PREV_PAGE:11004,,24
See the function import section there.
Note: Only the first REF CURSOR in a stored procedure is used by the Import Function dialog. It becomes the return value of the imported Entity Function by convention. You may need to create a wrapper stored procedure to set this up.