MVC Scaffolding Help

Hi All,

I have an entity framework Db Model being held in one solution (project1) a class library and the MVC website (using Identity) held in a second (project2). I have added the reference of project1 to project2. Now I know the connection to the (MySQL by the way) db is working, as I can compile project2 and register a new user using the default layout provided.

I now want to scaffold our some of the CRUD views, etc. But unfortunately I'm having some issues. Heres what I have done;

I right click on project2 and add new scaffolded Item. (In this case I am trying to add the ability to add roles to the Identity model).

I select 'MVC 5 controller with views, using entity framework'.

I then call the controller RolesController.

I select the AspNetRoles table from project1.

If i select the connection string from the MVC project (this is the extending the IdentityDbContext in project2 Models) which is held in the web.config file. I get the following error;

Error

There was an error running the selected code generator:

'There was an error in compilation of the type 'GetTalent.Models.ApplicationDbContext'.

CS0246: The type or namespace name 'ApplicationUser' could not be found (are you missing a using directive or an assembly reference?)'

Open in new window


Now ApplicationUser does exist in this namespace. Here is the full IdentityModel.cs

namespace GetTalent.Models
{
    public class ApplicationUser : IdentityUser
    {
    }

    [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("AshtonMediaDb")
        {
        }
    }
}

Open in new window


However I use the connection from the app.config in the class library of (project1 DbContext) i get the following error;

There was an error running the selected code generator:

'Unable to retrieve metadata for 'EntityFrameworkDb.AspNetRole'. Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.'

Open in new window


any ideas whats going on here?
flynnyAsked:
Who is Participating?
 
Bob LearnedCommented:
What is the difference between the connection strings (without private information included)?
0
 
flynnyAuthor Commented:
nothing they are exactly the same.

one is in te class library for the entity class library to build from and the other is just in the MVC project for runtime.
0
 
Bob LearnedCommented:
How are you passing in the connection string to the data context?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.