现在 ODP.net 提供两个版本.
-
ODP.NET Managed Driver(不需要 Oracle Client), 所有访问的功能都集成在单一的 Oracle.ManagedDataAccess.dll文件中
-
ODP.NET unmanaged driver (需要 Oracle Client), 通常建议安装轻量级的 Oracle Instant Client .
-
dotnet(Core) 对应的托管driver包名为: Oracle.ManagedDataAccess.Core
-
dotnet(Framework) 对应的托管driver包名为: Oracle.ManagedDataAccess
安装命令:
dotnet add package Oracle.ManagedDataAccess.Core
或者:Install-Package Oracle.ManagedDataAccess.Core 该package的依赖有:System.Formats.Asn1 System.Security.Cryptography.ProtectedData System.Diagnostics.PerformanceCounter System.Diagnostics.EventLog System.Security.Cryptography.Pkcs System.DirectoryServices.Protocols Oracle.ManagedDataAccess.Core System.Diagnostics.EventLogSystem.Configuration.ConfigurationManager
下面是一个安装ODP driver后的csproj文件示例:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable></PropertyGroup><ItemGroup><PackageReference Include="Oracle.ManagedDataAccess.Core" Version="23.7.0" /></ItemGroup>
</Project>
常用的数据类型对应关系为:
- C# int → OracleDbType.Int32
- C# string → OracleDbType.Varchar2
- C# DateTime → OracleDbType.Date
- C# decimal → OracleDbType.Decimal
- C# byte[] → OracleDbType.Blob