I added a database to my project, then I want to add a controller.
When the Add Controller window pops up, I am asked to choose Data context class.
Surprisingly, I found that there are 2 context classes: One is called: my_database_name_dbEntities(projectname)
Another one is called:
ApplicationDbContext(projectname.Models) which is what I created when I added the Entity Framework object which connects to my database.
I am confused about
- which one to use
- what are the differences
Here is the screenshot
Update
I tried both of them and here is what I have got:
- If I choose the databasename_dbEntities, VS generates views and controller perfectly with no problems.
- If I choose ApplicationDbContext, VS throws an error:
Error
There was an error running the selected code generator:
'Unable to retrieve metadata for 'lrc.Event'. One or more validation errors were detected during model generation:
AspNetUserLogin: : EntityType 'AspNetUserLogin' has no key defined. Define the key for this EntityType.
AspNetUserLogins: EntityType: EntitySet 'AspNetUserLogins' is based on type 'AspNetUserLogin' that has no keys defined.
'
Update
Now, I changed the super class from DbContext to IdentityDbContext for the projectname_dbEntities. So it looks like this now:
public partial class projectname_dbEntities : IdentityDbContext<ApplicationUser>
{
public projectname_dbEntities()
: base("projectname_dbEntities", throwIfV1Schema: false)
//: base("name=projectname_dbEntities")
{
}
public static projectname_dbEntities Create()
{
return new projectname_dbEntities();
}
.....
}
I wonder :
what are the advantages of using the the derived class from IdentityDbContext over the DbContext?