I have searched the web and reviewed similar questions on Stack Overflow but I can not figure how to use the Oracle Managed Data Provider with a DbContext from a C# .Net 4.6 Console Application.
This works for Sql Express
class SqlDBContext1 : DbContext
{
public SqlDBContext1() : base("SqlExpressDB")
{
using (var ctx = this)
{ var query = from c_codes in ctx.CountryCodes select c_codes; }
}
public DbSet<CountryCode> CountryCodes { get; set; }
}
And this works to connect to a remote Sql Server, using a connection string
class SqlDBContext2 : DbContext
{
public SqlDBContext2() : base(SqlServerString())
{
using (var ctx = this)
{ var query = from c_codes in ctx.CountryCodes select c_codes; }
}
public DbSet<CountryCode> CountryCodes { get; set; }
private static string SqlServerString()
{
return @"Data Source=192.168.0.1;" +
"Initial Catalog=SqlDB1; " +
"Persist Security Info=True; " +
"User ID=USER1; " +
"Password=PASS1";
}
}
I can connect to Oracle from Visual Studio 2017 and I have verified the connection string using a standard OracleConnection, it opens and closes, no problem.
With this in the APP.CONFIG
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="ORCL1" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL1))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
<connectionStrings>
<add name="ORCL1DB" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=USER1;Password=PASS1;Data Source=ORCL1"/>
</connectionStrings>
Can I use something like this? If so, what goes into the DbContext's base contructor?
class OraDBContext : DbContext
{
public OraDBContext() : base("What goes here")
{
using (var ctx = this)
{ var query = from c_codes in ctx.CountryCodes select c_codes; }
}
public DbSet<CountryCode> CountryCodes { get; set; }
}
None of the examples I have found on Stack Overflow work, various errors of which 'Type Initializor threw an exception' being the most popular.