Doubt with Entityframework (Migration)

Asked

Viewed 266 times

2

I’m trying to make my code run, but I’m not getting it because of this Error

Severity Code Description Project File Line Error CS0311 The type 'Controleinterno.Migrations.Controleinterno.Controleintcontexto' cannot be used as type Parameter 'Tcontext' in the Generic type or method 'Dbmigrationsconfiguration'. There is no implicit Reference Conversion from 'Controleinterno.Migrations.Controleinterno.Controleintcontexto' to 'System.Data.Entity.Dbcontext'. Controleinterno F: Documents Visual Studio 2015 Projects Internal Control Controleinterno Migrations Configuration.Cs 6

using ControleInterno.Model;
using System.Data.Entity;

namespace ControleInterno
{
    class ControleIntContexto : DbContext
    {
        public ControleIntContexto()
        {
            Configuration.LazyLoadingEnabled = false;
        }

        public DbSet<Produto> Produtos { get; set; }
    }
}

Follow the code from the Configuration.Cs file

namespace ControleInterno.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<ControleInterno.ControleIntContexto>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(ControleInterno.ControleIntContexto context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}
  • I don’t understand why he doesn’t recognize my kind of context...

  • Place the code of your context class

  • I used this tip [http://stackoverflow.com/questions/11918401/enable-migrations-error-project-failed-to-build] and it worked. I wonder what the effects of that are?

  • 3

    Also enter the code of the configuration class you deleted. The explanation is in it.

1 answer

1


This here was generating ambiguity of names:

namespace ControleInterno
{
    class ControleIntContexto : DbContext
    { ... }
}

How did you remove the context of namespace right from him (ControleInterno.Models), note that the compiler solved the context name as follows:

ControleInterno.Migrations.ControleInterno.ControleIntContexto

And that’s obviously wrong.

Just change the namespace of the context and correct the references that returns to function.

  • It worked @Ciganomorrisonmendez . As amazing as it sounds, I didn’t change anything. When I gave Enable-Migrations it already generated so.

  • This problem is not really simple. I noticed it by its error message.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.