Separating Models in ASP.NET MVC with Entity Framework and Identity

asp.net-identity asp.net-mvc c# entity-framework entity-framework-6

Question

Using Visual Studio 2017. I am following a tutorial (based on a previous version of VS if that makes any difference) which has created a standard ASP.NET MVC project with Identity. As I understand it, it installs Entity Framework as well by default.

I now want to separate the models into a separate class Library. The Models folder currently represents the standard models that come when creating a new ASP.NET MVC "out of the box" project. So I add new empty CL project and move all the Model classes as shown here:

enter image description here

I add two additional classes as I would like to use the existing models and the new classes would represent new tables within my database.

At the moment I get compile errors about references not being available i.e.

The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

Looked at my assemblies and they are all empty which eventually led me to

Visual Studio 2017 won't load .NET Framework references in .NET Standard library

  1. This makes me wonder if I may have done this wrong or missed a step somewhere; how do I separate the model classes from an ASP.NET MVC project and put them into a new class library, so this class can be used against other projects?

  2. I would have 3 projects in total, Models (all class/database table models), Business Layer (where I would do CRUD operations) - would I install Entity Framework 6.4 into this class project? Then reference these two projects within the main ASP.NET MVC project?

1
0
12/21/2019 1:48:42 PM

Popular Answer

You need install the following nuget packages in your class library:

  1. Microsoft.AspNet.Identity.EntityFramework
  2. Microsoft.AspNet.Identity
  3. Microsoft.AspNet.Mvc
0
12/22/2019 1:54:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow