我试图将ASP身份整合到我自己的DbContext中,但我没有运气。我想要实现的是每个已发布的交易,用户都将被分配给它。
的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();
}
}
我已尝试更换&#34; DefaultContext&#34;到&#34; ShareDealsContext&#34;在ApplicationDbContext中,但仍然无法正常工作。我想完全删除DefaultContext并使用我自己的ShareDealsContext。关于我错过的任何想法?谢谢
答案 0 :(得分:0)
你可以用web.config中的连接字符串名替换DefaultContext吗?
public ApplicationDbContext() : base("CONNECTION_STRING_NAME", throwIfV1Schema: false)
例如,
的Web.config