Assume we have an ASP.NET MVC3 Web site that makes use of Entity Framework Code First approach to working with database.
The system is now working in test environment.
If the part of the DbContext is the following:
public DbSet<Incident> Incidents { get; set; }
will it cause DB-Code collaboration problems, if I, for example, add Properties to an Incident class?
Or will the framework just update the Database tables automatically, and will treat the older records, that were created without new properties as if they are null?
It depand on your database initialization setting.
(CreateDatabaseIfNotExists, DropCreateDatabaseWhenModelChanges, DropCreateDatabaseAlways)
eg: Database.SetInitializer(new CreateDatabaseIfNotExists())
If you didn’t set any database initialization, EF will use default
initlizer “CreateDatabaseIfNotExists” and it would throw
InvalidOperationError.
If you set as “DropCreateDatabaseWhenModelChanges“, EF will recreate
the Database based on your new Model. But you will also need necessary
access right to create the database and it is dangerous if you are in
production environment.
If you set as “DropCreateDatabaseAlways“, EF will recreate the Database whenever
you run the application.