开发者

C# Class and Oracle Mapping Parameters

开发者 https://www.devze.com 2023-02-06 10:17 出处:网络
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 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 to this type in C# like so

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

The above code works without error, however if I remove the schema name 'DEV_SCHEMA' from the attribute, 开发者_运维问答it fails:

[OracleCustomTypeMapping("OBJ_PROJECT_CODE_CHANGE")]

Generates the following error:

Unhandled Exception: System.InvalidOperationException: Custom type mapping for 'ProjectCodeChangeDTO' is not specified or is in valid.

at Oracle.DataAccess.Types.OracleUdt.GetUdtName(String customTypeName, String dataSource)

At some point I will want to ship the code past 'DEV_SCHEMA', but this will result in the code failing.

The schema name comes from the connection string User Id:

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

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

  1. Pass the schema name as the attribute parameter
  2. Define the type in Oracle in a way that I don't need to use the schema

As a further bit of information, this problem presents itself when I use the ODP.NET client version 11.1.0.7. The 11.2 version of the DLL works perfectly without the schema name in the attribute.

Any help would be much appreciated.


If you don't need to stick to the OracleCustomTypeMapping attribute approach, I think the best solution would be to set the custom type mappings through a configuration file, instead.


I have handled this in the past by 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 so:

[OracleCustomTypeMapping(OracleConfig.SCHEMA + "OBJ_PROJECT_CODE_CHANGE")]
0

精彩评论

暂无评论...
验证码 换一张
取 消