简体   繁体   中英

Calling oracle package/procedure using Entity Framework

Doing exactly the same in this LINK

I am trying to call an Oracle procedure/package using Entity Framework. But I am getting a different error than the one mentioned in the link.

Code

public List<ClearTypes> GetOffices()
{
     var param1 = new OracleParameter("P_CUR", OracleDbType.RefCursor, ParameterDirection.Output);           
     var ATests = this.Database.SqlQuery<ClearTypes>("BEGIN PRC_GET_CLEAR(:P_CUR); end;", param1).ToList();            
     return ATests;
}

SQL query:

BEGIN
    OPEN P_CUR FOR

    SELECT ID, Name FROM ClearType;

END

ClearType class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCApp2.Models
{
    public class ClearTypes
    {
       public int ID{get;set;}
       public string Name{ get; set; }
    }
}

The error what I get when running the application is:

An exception of type 'System.ArgumentException' occurred in System.Data.Entity.dll but was not handled in user code

Additional information: Value does not fall within the expected range.

What might be the reason for this?

This will work if you add Oracle managed data access package from Nuget packages in Visual studio.

using OracleParameter from Oracle.ManagedDataAccess.Client; will not throw error.

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