其他分享
首页 > 其他分享> > .netcore+ef+orcle+内置ioc容器

.netcore+ef+orcle+内置ioc容器

作者:互联网

  1. 添加引用

 

 

 

 

 

在程序包管理器控制台输入:Scaffold-DbContext "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP地址)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=服务名称)));User Id=用户名;Password=密码;" Oracle.EntityFrameworkCore -O  Models  -F

 

生成modelcontext

 3.配置appsettings.json

"ConnectionStrings": {
"OraCon": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP地址)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=服务名称)));User Id=用户名;Passwordf=;"
}

配置startup

public Startup(IConfiguration configuration)

        {

            Configuration = configuration;

 

            var path = Directory.GetCurrentDirectory();

            new ConfigurationBuilder().SetBasePath(path).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();

        }

 

public void ConfigureServices(IServiceCollection services)

        {

            services.AddControllersWithViews();

            services.AddSession();

            services.AddDbContext<ModelContext>(opt => opt.UseOracle(Configuration.GetConnectionString("OraCon")));//加载数据库连接

            

        }

4.配置ef生成的语句的监控日志

在ModelContext

 

 

 

 

 

 

可在输出查看 执行语句

 

 

 

 

4.ModelDbContext里声明oralce哪个版本,这里用的是11

 

 

 

 

5.测试使用

 

 

----------------------

 

内置ioc容器使用

在contrall配置依赖注入

 

 

 start.up里声明生命周期

 

标签:opt,orcle,netcore,ADDRESS,ef,SERVER,CONNECT,IP地址,services
来源: https://www.cnblogs.com/penpeng/p/15231802.html