I've been looking for this strange error for hours but haven't found anything. I have a very simple entity:
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 running the first time, everything works just fine. But, when I change the entity (for example, I put the [Key] attribute for Id), I get the expected "model has changed" or something error. So, I enter this in the Global.asax application_start:
Database.SetInitializer<MyDBContext>
(new DropCreateDatabaseIfModelChanges< MyDBContext >());
This is where I get stuck. There is no compile error, it compiles 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. Please review the stack trace for more information about the error and where it originated 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, does someone have a clue? I'm using Entity Framework 4.1 (CTP5)
For the unanswered question trawlers, this has been answered above. But never marked by users. See comments above. Over 1K views ! Thats wasting a lot of time... So i added this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With