Search code examples
c#oracleentity-frameworkldapodp.net

How to configure Entity Framework with LDAP?


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.


Solution

  • 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>