简体   繁体   中英

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

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:

在此处输入图片说明

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 ie

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?

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

  1. Microsoft.AspNet.Identity.EntityFramework
  2. Microsoft.AspNet.Identity
  3. Microsoft.AspNet.Mvc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM