如何使用 LDAP 配置 Entity Framework?

How to configure Entity Framework with LDAP?

我想要一个示例代码,了解如何设置允许 EF 通过 LDAP 连接映射来自 Oracle 数据库的实体的配置文件。我读过的大多数文档都同意 <LDAPSetting> 标签,但对 <connectionStrings> and/or <entityFramework> 标签只字不提。到目前为止,这就是我得到的。

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

任何样本都会有很大帮助。

检查你的语法,应该是这样的:

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

有关详细信息,请参阅 Configuring Oracle Data Provider for .NET

关于 LDAP 和 ODP.NET Managed Provider 也检查这个问题:

阅读一些文档后,我注意到有两种设置 LDAP 的方法。因此,这不是 "should" 的问题,而是 "which" 对您有用。正如@Wernfried 建议的那样,我使用了 <setting> 标签并根据此 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 并且它起作用了。

至于<connectionStrings>就这么简单:

<connectionStrings>
  <add name="Source" connectionString= "Data Source=ServiceName;password=your_password;User ID=your_user" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
  • 来源:来源名称。
  • ServiceName: 您要连接的 Oracle 服务。

至于 Entity Framework,我保留了 NuGet 包安装程序配置的默认设置。在我的项目中,我安装了 Official Oracle ODP.NET、Managed DriverOfficial Oracle ODP.NET、Managed Entity Framework Driver NuGet 包。

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