C#连接oracle数据库

C#连接oracle数据库的步骤:

1、创建继承DbContext的类,用OnConfiguring或者方式配置数据库连接信息:

public class AppDbContext : DbContext

    {

        public AppDbContext() { }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        {

            base.OnConfiguring(optionsBuilder);

            optionsBuilder.UseOracle("DATA SOURCE=127.0.0.1:1521/ORCL;PASSWORD=XXX;PERSIST SECURITY INFO=True;USER ID=XXX",b => b.UseOracleSQLCompatibility("11"));

        }

        public DbSet news { get; set; }

        public DbSet comments { get; set; }

    }

2、在Startup.cs的ConfigureServices方法中添加:

services.AddDbContext();

或services.AddTransient();

你可能感兴趣的:(C#连接oracle数据库)