摸索了半天,运行通过了,但是还是有一点坑的,对于初次使用的人来说,可能会遇到几个问题
首先安装两个dll
如果你已经下载好了dll
Oracle.ManagedDataAccess.dll
Oracle.ManagedDataAccess.EntityFramework.dll
可以直接引用
接下来就是配置文件
配置文件的写法网上有好几个版本的,发现每个版本似乎都可以?提供一个版本,这些是必须的配置
<configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/> </configSections> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb"/> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/> </providers> </entityFramework>
<system.data> <DbProviderFactories> <remove invariant="Oracle.ManagedDataAccess.Client"/> <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/> </DbProviderFactories> </system.data>
<add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=test;Password=test;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XE)));PERSIST SECURITY INFO=True;"/>
用户权限的问题
最好给用户都赋予resource和dba权限,否则EF查询数据的时候只能查到自己插入的,查询不到sysdba用户插入的数据。插入数据的时候也会出现这种问题,如果你发现数据不同步,请检查用户权限问题。
schema的问题
[Table("BOOK",Schema ="TEST")] public class Book { [Key] public string NAME { get; set; } public int PRICE { get; set; } }
大小写的问题
EF生成的语句时代了“”的,带了引号后,区分了大小写,所以实体字段、表名、Schema一定要和数据库一致