0

I would like to have a sample code on how to set up a config file that allows EF to map entities from an Oracle DB over LDAP connection. Most of the documentation I have read agree about about the <LDAPSetting> tag but say nothing about the <connectionStrings> and/or <entityFramework> tags. So far, this is what I have got.

<oracle.manageddataaccess.client>
    <version number="*">
      <LDAPsettings>  
        <LDAPsetting name="DIRECTORY_SERVERS" value="(serverX:3060:3131,serverY:3060:3131,serverZ:3060:3131,serverQ:3060:3131)"/>  
        <LDAPsetting name="DIRECTORY_SERVER_TYPE" value="oid"/>  
        <LDAPsetting name="DEFAULT_ADMIN_CONTEXT" value="cn=OracleContext,dc=mydomain,dc=com"/>  
      </LDAPsettings>  
      <settings>  
        <setting name="NAMES.DIRECTORY_PATH" value="(LDAP)"/>  
      </settings>      
    </version>
  </oracle.manageddataaccess.client>

Any sample will be a great help.

dotnetspark
  • 551
  • 4
  • 23

2 Answers2

1

Check your syntax, it should be like this:

<oracle.manageddataaccess.client>
    <version number="*">
      <LDAPsettings>  
        <setting name="DIRECTORY_SERVERS" value="(serverX:3060:3131,serverY:3060:3131,serverZ:3060:3131,serverQ:3060:3131)"/>  
        <setting name="DIRECTORY_SERVER_TYPE" value="oid"/>  
        <setting name="DEFAULT_ADMIN_CONTEXT" value="cn=OracleContext,dc=mydomain,dc=com"/>  
      </LDAPsettings>  
     <settings>  
        <setting name="NAMES.DIRECTORY_PATH" value="(LDAP)"/>  
      </settings>      
    </version>
  </oracle.manageddataaccess.client>

See Configuring Oracle Data Provider for .NET for more details.

Regarding LDAP and ODP.NET Managed Provider check also this issue: ODP.NET Managed library does resolve alias, but 32-bit library does

Community
  • 1
  • 1
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • Thanks for your help with the configuration @wernfried-domscheit. As for the last link, I wish it could help but, unfortunately I am not using Oracle Client as ODP.NET Managed Driver is fully managed. Therefore, Oracle Client could be opt-out. Also I would like your input on how to configure Entity Framework with the above LDAP settings. Thanks in advance. – dotnetspark May 14 '16 at 23:04
0

After reading some documentation, I've noticed there are two ways of setting up LDAP. Therefore, it is not a matter of "should" but "which" works for you. As @Wernfried suggested I have used the <setting> tag and according to this reference it's fine. However, for some reason I don't know it didn't work to me. Instead I left the initial <LDAPsetting> tag as pointed in LDAPSettings section here and it worked.

As to the <connectionStrings> it was as simple as follow:

<connectionStrings>
  <add name="Source" connectionString= "Data Source=ServiceName;password=your_password;User ID=your_user" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
  • Source: The name for the source.
  • ServiceName: The Oracle Service you want to connect to.

As to the Entity Framework, I kept the default settings as configured by the NuGet package installer. In my projects I've installed the Official Oracle ODP.NET, Managed Driver and the Official Oracle ODP.NET, Managed Entity Framework Driver NuGet packages.

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="v12.0"/>
    </parameters>
  </defaultConnectionFactory>
  <providers>
    <provider invariantName="Oracle.ManagedDataAccess.Client" 
            type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </providers>
</entityFramework>
dotnetspark
  • 551
  • 4
  • 23