I searched for this strange error for hours, but found nothing. I have a very simple object:
public class Company { public Guid Id { get; set; } public string Name { get; set; } }
And here is the context:
public class MyDBContext : DbContext { public DbSet<Company> Companies { get; set; } }
When starting for the first time, everything works fine. But, when I change the entity (for example, I put the [Key] attribute for Id), I get the expected โmodel changedโ or something confusing. So, I introduced this into the Global.asax application_start application:
Database.SetInitializer<MyDBContext> (new DropCreateDatabaseIfModelChanges< MyDBContext >());
This is where I am stuck. A compilation error does not compile without errors / warnings. But when I run my project, I get the following error:
Description: An unhandled exception occurred during the execution of the current web request. Check the stack trace for more information about the error and where it appeared in the code.
Exception Details: System.TypeLoadException: GenericArguments[0], 'MyDB.Data.MyDBContext', on 'System.Data.Entity.IDatabaseInitializer1[TContext]' violates the constraint of type parameter 'TContext' .
Please someone have a key? I am using Entity Framework 4.1 (CTP5)
user825887
source share