Error trying to register in C#

Asked

Viewed 118 times

0

I am creating a program and I need the user to register to log in. When running the program, when I try to register this error appears in Visual Studio: "The model backing the 'Banco' context has changed Since the database was created." This error points this part of the code in the first line (User ...):

public bool Login(String login, String senha)
    {
        Usuario usuario = this.banco.Usuarios.Where(user => user.Email.Equals(login) && user.Senha.Equals(senha)).FirstOrDefault();

        Gerenciador.usuarioLogado = usuario;

        return (usuario != null);
    }

Here is the beginning of the code:

public class Gerenciador
{

    public static Usuario usuarioLogado;

    private Banco banco = new Banco();
 (...)

Please help me. I need to deliver this program this week and I can’t even log into the program :x

Thank you in advance!

1 answer

0

Try adding this code snippet in your class that represents the context of the database application:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
     Database.SetInitializer<NomeDoSeuContexto>(null);
     base.OnModelCreating(modelBuilder);
}
  • It worked, but has now switched to "System.Data.Entity.Core.Entitycommandexecutionexception: 'An error occurred while executing the command Definition. See the Inner Exception for Details. ' " Continued aimed at the same stretch... :s

  • Your schema Has the database changed since you last logged in? Both on the C# (EF Code First) and SQL Server sides? If yes, you have to synchronize the change in the part that has not yet been changed.

  • Marcelo, I’m not sure because I have another colleague modifying as well. ?

  • If SQL Server has won/lost tables or columns, this should be reflected in Code First and vice versa. This is the synchronization.

  • I get it. I’m gonna look for this

Browser other questions tagged

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