Possible to access DbConfiguration from DbContext?

Viewed 522

Having my own EF DbContext derived class associated with my own DbConfiguration derived configuration class:

[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyDbContext : DbContext
{
}

I'm trying to access the instance of the MyDbConfiguration from within MyDbContext.

(Assuming that there actually is any instance at all).

E.g.:

public class MyDbConfiguration : DbConfiguration
{
    public int SomeProperty { get; set; }
}

and

[DbConfigurationType(typeof(MyDbConfiguration))]
public class MyDbContext : DbContext
{
    public int SomeMethod()
    {
        // This lines fails to compile:
        var config = (MyDbConfiguration)Configuration;

        config.SomeProperty = 42;
    }
}

The compilation error is:

Cannot convert type 'System.Data.Entity.Infrastructure.DbContextConfiguration' to 'MyDbConfiguration'.

Obviously, there is no direct relationship beween these two types.

Most likely I'm completely misunderstanding this Entity Framework configuration stuff and this question is an XY problem. Still I'm kindly trying to ask it:

My question:

Is there any way to access the DbConfiguration from within a DbContext?

If not, is it possible the other way around? I.e. access the DbContext from within a DbConfiguration?

(This question is related to EFCache issue #14)

1 Answers
Related