C # and Oracle class options

I have a type declared in an Oracle database:

CREATE OR REPLACE TYPE t_project_code_changes AS TABLE OF obj_project_code_change; 

I map this type to C # like this:

 [OracleCustomTypeMapping("DEV_SCHEMA.OBJ_PROJECT_CODE_CHANGE")] class ProjectCodeChangeFactory : TypeFactoryTemplate<ProjectCodeChangeDTO> { //code } 

The above code works without errors, however, if I remove the schema name "DEV_SCHEMA" from the attribute, this will not work:

 [OracleCustomTypeMapping("OBJ_PROJECT_CODE_CHANGE")] 

It raises the following error:

Unhandled exception: System.InvalidOperationException: Custom type mapping for 'ProjectCodeChangeDTO' not specified or valid.
in Oracle.DataAccess.Types.OracleUdt.GetUdtName (String customTypeName, String dataSource)

At some point I will want to send the code for "DEV_SCHEMA", but this will lead to a code failure.

The schema name comes from the User Id connection string:

 "Data Source=DBNAME;User id=DEV_SCHEMA;Password=pwd;Pooling=False;" 

Is there anything I can do with Oracle on the C # side to help me with this. Ie, somehow:

  • Pass the schema name as an attribute parameter
  • Define a type in Oracle so that I don't need to use a schema

As additional information, this problem occurs when I use the client version of ODP.NET version 11.1.0.7. Version 11.2 of the DLL works fine without the schema name in the attribute.

Any help would be greatly appreciated.

+4
source share
2 answers

If you do not need to adhere to the OracleCustomTypeMapping attribute OracleCustomTypeMapping , I believe that the best solution would be to establish custom type mappings through the configuration file.

+2
source

I have handled this in the past using the following:

 internal static class OracleConfig { #if SHIPPING internal const string SCHEMA = @"REL."; #else internal const string SCHEMA = @"DEV."; #endif } 

Then you can use it like this:

 [OracleCustomTypeMapping(OracleConfig.SCHEMA + "OBJ_PROJECT_CODE_CHANGE")] 
+2
source

Source: https://habr.com/ru/post/1336983/


All Articles