Function imports for entity framework with odp.net managed driver

三世轮回 提交于 2019-12-06 12:26:14

问题


I recently switched from ODP Unmanaged to ODP Managed (in conjunction with Entity Framework). The Unmanaged drivers were working fine after adding the necessary information in the web.config section. I could add the stored procedures and generate the complex types using the Function Import - Get Column information (I'm trying to import a stored procedure with an OUT refcursor parameter). After the switch the config section was updated to reflect the new format and everything works at runtime (so the format is correct).

However when I try to generate the complex types again (or add a new Function Import) I just get a System.notSupportedException Message: The specified type is not supported by this selector) Without any indication which type/selector it is (obviously)...

Google has turned up nothing and the thread on the Oracle Forums has gathered no response as well.

Versions: ODP.Net (ODAC) : v12.1 (Production release; DLL v4.121.1.0) EF v5 .NET v4.5 Config file (trimmed a bit):

<configSections>
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess"/>
</configSections>
<oracle.manageddataaccess.client>
    <version number="*">
        <edmMappings>
            <edmMapping dataType="number">
                <add name="bool" precision="1"/>
                <add name="byte" precision="2" />
                <add name="int16" precision="5" />
                <add name="int32" precision="10" />
                <add name="int64" precision="38" />
            </edmMapping>
        </edmMappings>
        <implicitRefCursor>
            <storedProcedure schema="ECOM" name="SHP_API_ORDERS.CREATE_ORDER">
                <refCursor name="O_RS">
                    <bindInfo mode="Output"/>
                    <metadata columnOrdinal="0" columnName="COL1" nativeDataType="Number" providerType="Decimal" allowDBNull="false" numericPrecision="10" numericScale="0" />
                    <metadata columnOrdinal="1" columnName="COL2" nativeDataType="Date" providerType="Date" allowDBNull="true" />
                    <metadata columnOrdinal="2" columnName="COL3" nativeDataType="Varchar2" providerType="Varchar2" allowDBNull="false" columnSize="10" />
                </refCursor>
            </storedProcedure>
        </implicitRefCursor>
    </version>
</oracle.manageddataaccess.client>
<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<system.data>
    <DbProviderFactories>
        <remove invariant="Oracle.ManagedDataAccess.Client" />
        <add name="ODP.NET, Managed Driver"
             invariant="Oracle.ManagedDataAccess.Client"
             description="Oracle Data Provider for .NET, Managed Driver"
             type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
</system.data>

回答1:


The implicit ref cursor config file format is different between Unmanaged ODP.NET and Managed ODP.NET. That might be part of your problem.

To save yourself from pulling your hair out, install the latest Oracle Developer Tools for Visual Studio (ODT) and use the new feature that automatically generates this config:

1) Install ODT 12.1 if you haven't already

2) Find the stored procedure in server explorer, right click it and run it, and enter input parameters.

3) For the output ref cursor that represents the return value for your Entity Function, choose "Add to Config" checkbox.

4) Then select either "Show Config" (and then cut and paste) or "Add to Config".

Here is a screenshot of what I am talking about:

http://i.imgur.com/t1BfmUP.gif

If this doesn't fix the problem, play around with that boolean mapping. I am not 100% sure of this as of this writing, but I remember hearing that support for booleans is another difference between managed and unmanaged ODP.NET. I'm sure it's buried in the release notes or doc somewhere.

Christian Shay

Oracle




回答2:


Two things you would want to try which might potentially solve the issue:

  1. Ensure the case of the schema name, stored procedure name and the column names in the config are the same as that in the Oracle.
  2. Try mapping the native type to a more conformant provider type, like the first column COL1 - map an int32 providerType to the number(10,0) nativeDataType as enforced by your edmmapping, instead of the Decimal that you currently have. And so forth for the other columns (like remove the column lengths) until you do not see the error or get a different one.



回答3:


I've got the same error and I think my problem is a providerType of DOUBLE or DECIMAL. But, I got one to work that has your 3 column types. Your problem is that a number(10,0) should be a providerType of "Int64".

Stored Procedure:

create or replace PROCEDURE "PROC_ESCC_FIELDS" (p_recordset OUT SYS_REFCURSOR)
AS
BEGIN
OPEN p_recordset FOR
  SELECT COL1, COL2, COL3
     FROM MyTable;
END PROC_ESCC_FIELDS;

This works and returns the cursor:

<oracle.manageddataaccess.client>
  <version number="*">
    <implicitRefCursor>
      <storedProcedure schema="SERFIS" name="PROC_V_SERFIS_ESCC_FIELDS">
        <refCursor name="P_RECORDSET">
          <bindInfo mode="Output" />
            <metadata columnOrdinal="0" columnName="COL1" providerType="Int64" allowDBNull="false" nativeDataType="Number" />
            <metadata columnOrdinal="1" columnName="COL2" providerType="Date" allowDBNull="true" nativeDataType="Date" />
            <metadata columnOrdinal="2" columnName="COL3" providerType="Varchar2" allowDBNull="false" nativeDataType="Varchar2" />
        </refCursor>
      </storedProcedure>
    </implicitRefCursor>
  </version>
</oracle.manageddataaccess.client>

Click here for a list of the providerType and nativeDataType, etc. ENUMS:



来源:https://stackoverflow.com/questions/19218397/function-imports-for-entity-framework-with-odp-net-managed-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!