Update model ADO.net C #

1

I would like to know how an ADO.NET model is updated since I felt the need to update my database but the project in Visual Studio C # tells me what it needs, so I would like to know the easiest way to update the model.

This line is the one where the error is where I send a table to be displayed so that it shows up in DropDownList :

public Array cargarCategorias() 
{ 
    return (MI.Categoria.Select(x => x.sNombre).ToArray()); //es aqui 
}
    
asked by Eric Mtz 13.10.2017 в 22:36
source

1 answer

0

This error is due to a change in your data model, whether you modified it or added components to your solution, or if applicable, the database underwent changes in its structure and the changes do not match the definitions of Entity Framework.

To solve this you must identify the class where your database is initialized, if your data model is called DataContext , then you can find it as DataContextInitializer , and then implement from System.Data.Entity.DropCreateDatabaseIfModelChanges

public class DataContextInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<DataContext>
{
    protected override void Seed(DataContext context)
    {
        SqlConnection.ClearAllPools();
        context.Database.CreateIfNotExists();
        System.Data.Entity.Database.SetInitializer(new NullDatabaseInitializer<DataContext>());
    }
}

With this, if your data model has undergone any changes, it would be forced to recreate the database to be able to maintain objects.

    
answered by 13.10.2017 в 23:08