[英]In an Asp.net project using identity v2 and Entity Framework how can I move all my code first models and User model identity to a new project
I have a web API 2 project and I use Entity Framework code-first models which has some foreign keys to identity version 2 users table that is bound to webapi 2 project. 我有一个Web API 2项目,我使用Entity Framework代码优先模型,该模型具有一些外键,用于标识绑定到webapi 2项目的版本2用户表。 Since I have another provider project I have a reference to provider in my service (web api 2) project and since provider needs a reference to models putting models in service project cause circular reference. 由于我有另一个提供者项目,因此我在服务(Web api 2)项目中引用了提供者,并且由于提供者需要引用将模型放入服务项目中的模型,因此会引起循环引用。
Long story short I need to be able to move the code first models to a new project called Models
to be used in both project. 长话短说,我需要能够将代码优先模型移到一个名为Models
的新项目中,以在两个项目中使用。 The problem is that no matter how hard I tried I couldn't move the IdentityUser
model to a separate project since it needs reference to Microsoft.AspNet.Identity.EntityFramework
问题是,无论我多么努力,我都无法将IdentityUser
模型移至单独的项目,因为它需要引用Microsoft.AspNet.Identity.EntityFramework
Below is an example of one of the models I use and ApplicationUser
derives from IdentityUser
: 以下是我使用的一种模型的示例,我从IdentityUser
派生了ApplicationUser
:
public class Application
{
public int ID { get; set; }
public string Name { get; set; }
public string Owner { get; set; }
public string Company { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PaymentInfo { get; set; }
public DateTime CreateDate { get; set; }
public DateTime ExpireDate { get; set; }
public virtual ApplicationUser User { get; set; }
public virtual ICollection<Billing> Billings { get; set; }
}
I had the same issue few months ago. 几个月前我遇到了同样的问题。
ApplicationUser has to be inherited from IdentityUser. ApplicationUser必须从IdentityUser继承。 And there is no other way to keep all models of your project in one class library project without using required references when you using Identity framework. 使用Identity框架时,没有其他方法可以将项目的所有模型保留在一个类库项目中,而无需使用必需的引用。
My suggestion is to use separate project (class library) to handle all the identity stuff rather than keeping it on your web API 2 project. 我的建议是使用单独的项目(类库)来处理所有身份信息,而不是将其保留在Web API 2项目中。 Then you can reference that project anywhere when you needed. 然后,您可以在需要时在任何地方引用该项目。 This will avoid having Web Api 2 project referencing on Models project. 这样可以避免在Models项目上引用Web Api 2项目。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.