I'm trying to use the c# interactive window to quickly test some of my code. I run into troubles when I try to test code related with DbContext (EF6).
I understand that I need to pass the connection string since the interactive window won't load the App.config file, so I have overridden the constructor that specifies the connection string.
I have also to say that I am using the Oracle database with the ODP.NET provider.
Here is the code I'm trying to run on the interactive window:
#r "MyProjPath\bin\Debug\CsCore.EntityDomain.dll"
#r "MyProjPath\bin\Debug\EntityFramework.dll"
#r "MyProjPath\bin\Debug\EntityFramework.SqlServer.dll"
#r "MyProjPath\bin\Debug\Oracle.ManagedDataAccess.dll"
#r "MyProjPath\bin\Debug\Oracle.ManagedDataAccess.EntityFramework.dll"
var ctx = new CsCore.EntityDomain.Pivot.PivotContext("Data Source=MyDataSource;User Id=MyUser;Password=MyPassword;");
ctx.ReconciliationRules.FirstOrDefault()
and this is the exception I get
The underlying provider failed on Open.
+ System.Data.Entity.Core.EntityClient.EntityConnection.Open()
+ System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(bool)
+ System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction<T>(Func<T>, System.Data.Entity.Infrastructure.IDbExecutionStrategy, bool, bool)
+ System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute<TResult>(Func<TResult>)
+ ObjectQuery<T>.GetResults(Nullable<System.Data.Entity.Core.Objects.MergeOption>)
+ LazyEnumerator<T>.MoveNext()
+ System.Linq.Enumerable.FirstOrDefault<TSource>(IEnumerable<TSource>)
+ System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle<TResult>(IEnumerable<TResult>, System.Linq.Expressions.Expression)
+ System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute<TResult>(System.Linq.Expressions.Expression)
+ System.Data.Entity.Internal.Linq.DbQueryProvider.Execute<TResult>(System.Linq.Expressions.Expression)
+ System.Linq.Queryable.FirstOrDefault<TSource>(IQueryable<TSource>)
My DbContext looks like this:
public class PivotContext : DbContext
{
public virtual DbSet<PivotReconciliationRule> ReconciliationRules { get; set; }
public PivotContext() : this("name=myConnectionStringName")
{
}
public PivotContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<PivotContext>(null);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MYSCHEMA");
base.OnModelCreating(modelBuilder);
}
}
I think that the reason is that I'm not able to specify the correct provider. Has someone managed to use code-first EntityFramework code (on oracle) working from the c# interactive window?
Many thanks in advance.
Nicola