locked
Entity Framework 7 - Problem with DbContext and initialization of data models RRS feed

  • Question

  • User-106190679 posted

    Hi everyone !

    I have a problem with EF7 RC1 update 1 DbContext and initialization of data models.

    I don't know why, some data models are visible into "Model" property of DbContext and others are "????".

    Here is my DbContext :

        public class MyDbContext : DbContext
        {
            private IConfigurationRoot configuration = null;
    
            public MyDbContext()
            {
                var builder = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .AddEnvironmentVariables();
                configuration = builder.Build();
            }
            
            protected override void OnModelCreating(ModelBuilder modelBuilder)
            {
                modelBuilder.HasDefaultSchema(configuration["Data:Schema"]);
            }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                var connectionString = configuration["Data:DefaultConnection:ConnectionString"];
                optionsBuilder.UseSqlServer(connectionString);
            }
        }

    If I comment "configuration = builder.Build();", Model property of DbContext is null. But if I uncomment this instruction, I have some data models into Model but non exhaustive.

    Do you know what is the link between "builder.Build()" and the initialization of Model (DbContext) ?

    Thank you for your help.

    Greg

    Tuesday, March 8, 2016 1:52 PM

All replies

  • User-811829503 posted

    I don't know why, some data models are visible into "Model" property of DbContext and others are "????".

    I don't know what you mean, could you please describe it in detailed.

    Do you know what is the link between "builder.Build()" and the initialization of Model (DbContext) ?

    please refer to:

    http://docs.asp.net/en/latest/fundamentals/configuration.html

    Wednesday, March 9, 2016 9:46 AM