1.**EntityFramework添加oracle ef相关nuget包 Oracle.ManagedDataAccess.EntityFramework(自动添加Oracle.ManagedDataAccess)
2.**Web添加Oracle.ManagedDataAccess.EntityFramework(自动添加Oracle.ManagedDataAccess)
3.**EntityFramework 下重写OnModelCreating方法
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("ORCL");//一定要大写 base.OnModelCreating(modelBuilder); }
4.修改**Web 下的web.config
<oracle.manageddataaccess.client> <version number="*"> <dataSources> <dataSource alias="ORCL" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " /> </dataSources> </version> </oracle.manageddataaccess.client>
<connectionStrings> <add name="Default" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=ORCL;Password=ORCL;Data Source=ORCL;Persist Security Info=true " /> </connectionStrings>
5.程序包管理控制台
5.1默认项目选项 选择**EntityFramework
5.2 执行Add-Migration 命令
5.3 执行update-database命令
注:遇到的一个坑,没做好上述步骤之前,执行了nuget命令 ,导致 生成了sqlerver的资源文件,所以一直报 没有dbo用户的错