Change data in migration Up method - Entity Framework

asp.net-mvc c# ef-migrations entity-framework

Question

My current model has a new property that I have added. It is a bool property with the value true by default. This table already contains data, and I want to immediately after establishing the new field in the Up function, set the new property for one particular row to false.

public override void Up()
    {
        AddColumn("dbo.RequestValidationErrors", "IsBreaking", c => c.Boolean(nullable: false));
        using (Context ctx = new Context())
        {
            var validation = ctx.RequestValidationErrorSet.FirstOrDefault(x => x.WordCode == "RequestValidationError.MoreThanOneItemFound");
            if (validation != null)
            {
                validation.IsBreaking = false;
                ctx.SaveChanges();
            }
        }
    }

Thus, while saying, EF throws an error.

System.InvalidOperationException: The model backing the 'DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database

Can I modify the database here, or need I go somewhere else?

1
46
1/13/2017 1:12:46 PM

Accepted Answer

ZZZ_tmp
58
4/12/2020 8:34:07 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow