【发布时间】:2014-10-09 02:13:50
【问题描述】:
我正在尝试将 ASP Identity 集成到我自己的 DbContext 中,但我没有运气。我想要实现的是,每个发布的交易都会分配一个用户。
数据库上下文:
public class ShareDealsContext : IdentityDbContext<ApplicationUser>
{
public ShareDealsContext() : base("name=ShareDealsContext")
{
}
// Other DbSets
public DbSet<Deals> Deals { get; set; }
}
交易模式:
[ForeignKey("User")]
public virtual string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
身份模型:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public virtual ICollection<Deals> Deals { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext() : base("DefaultContext", throwIfV1Schema: false) { }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
我尝试在 ApplicationDbContext 中将“DefaultContext”替换为“ShareDealsContext”,但仍然无法正常工作。我想完全删除 DefaultContext,只使用我自己的 ShareDealsContext。关于我错过了什么的任何想法?谢谢
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework asp.net-mvc-5