【发布时间】:2016-04-24 02:22:15
【问题描述】:
我想使用默认的 Identity 2 提供程序构建 N-tire Web 应用程序。因此,我的数据层包含具有模型定义的纯 c# 类,没有任何外部依赖项。但是如果不添加 AspNet.Identity 引用,就不可能将某些类链接到我的应用程序用户。
我已经尝试做一个用户类的接口:
public interface ISystemUser
{
string Id { get; set; }
string Title { get; set; }
}
public class Place
{
public int Id { get; set; }
public string Address { get; set; }
public ISystemUser User { get; set; }
}
在基础设施层用实现代替它:
public class ApplicationUser : IdentityUser, ISystemUser
{
public string Title { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
{
}
public DbSet<Place> Places { get; set; }
}
但实体框架不会创建实体之间的关系。
是否有任何“正确”的方式来实现这一点,或者是否需要添加参考?
【问题讨论】:
标签: c# asp.net entity-framework architecture asp.net-identity