I am working with entity framework with code fist design pattern.
First of all I created two tables classes …
using System.Data.Entity;
public class CyclingClubContext:DbContext
{
public DbSet<CycleType> CycleType { get; set; }
public DbSet<CycleModel> CycleModel { get; set; }
}
When I run my project,
It create two tables at database which is auto-generated as CyclingClub.sdf file.
Then , I need to add another entity class.
So, After I created new my entity class, I modify Context class like that …
using System.Data.Entity;
public class CyclingClubContext:DbContext
{
public DbSet<CycleType> CycleType { get; set; }
public DbSet<CycleModel> CycleModel { get; set; }
public DbSet<SideMenu> SideMenu { get; set; }
}
Then, I build my project, but it still show that build success message.
But when I run my project, problem start happen by showing message that
[InalidOperationException was unhandled by user code.]
The model backing the 'CyclingClubContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
So now I have more than one question.
1)How can I solve this error?
2)Whenever we need to add new entity class, do we need to delete existing database first
and recreate the database as error message already suggest me?
3)If we need to delete first and recreate the new database , then I afraid that my
existing record(s) will lose after recreate the new database. What will be the best solution?
4)Is SDF file really reliable one when we want to go enterprise level? If so let me know the reason why?
5)MDF file and SDF file , which one is better for enterprise level which need to deal with
large volume of data and multiple users access at single time?
6)Is this possible to use MDF file in entity framework code first design pattern?
If so let me know the reference links which showing how?
Every suggestion will be really appreciated.
Seedmethod to fill your newly created database with some initial data.You can think that my answers are not detailed enough but that is because you are asking too many questions in one thread.
Just follow this set of articles to learn about code first. It targets pre-release version but almost all content should be valid.