Entity Framework 6 Oracle DbConfiiguration
不想配置Entity Framework 6的App.Config文件时,要重写DbConfiguration,还要AppConfig当中的所有关于EntityFramework的所有配置项删除,不然DbConfiguration不会生效。
public class MyDbConfiguration : DbConfiguration
{
public InMindDbConfiguration()
{
SetDefaultConnectionFactory(new OracleConnectionFactory());
SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
SetProviderFactory("Oracle.ManagedDataAccess.Client", new OracleClientFactory());
}
}
[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyDbContext : DbContext
{
private const string ConnectionString = "User Id=xxx;Password=xxx;Data Source=Oralce";
static MyDbContext ()
{
//配置TNS路径
//OracleConfiguration.TnsAdmin = @"c:\odtnet\network\admin";
//配置初始化器
//Database.SetInitializer(new MyCreateDatabaseInitializer());
}
public MyDbContext() : base(ConnectionString)
{
}
}
标签:Entity,Framework,DbConfiguration,Oracle,DbConfiiguration,public
From: https://www.cnblogs.com/nolyn-shen/p/16914273.html