Oracle Entity Framework - Call custom function (EDIT_DISTANCE)

后端 未结 3 406
花落未央
花落未央 2021-01-13 09:18

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?

3条回答
  •  长情又很酷
    2021-01-13 09:35

    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:

    var ctx = new TestContext();
    var cmd = ctx.Database.Connection.CreateCommand() as OracleCommand;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "SOMESTOREDPROC";
    var p_rc1 = new OracleParameter("p_rc1", OracleDbType.RefCursor, ParameterDirection.Output);
    var p_rc2 = new OracleParameter("p_rc2", OracleDbType.RefCursor, ParameterDirection.Output);
    cmd.Parameters.Add(p_rc1);
    cmd.Parameters.Add(p_rc2);
    
    if (ctx.Database.Connection.State != ConnectionState.Open)
        ctx.Database.Connection.Open();
    
    var reader = cmd.ExecuteReader(); 
    

    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.

提交回复
热议问题