gpt4 book ai didi

asp.net-mvc - 您自定义数据库 IdentityDbContext

转载 作者:行者123 更新时间:2023-12-04 04:35:39 26 4
gpt4 key购买 nike

我试图开发一个应用程序并创建我自己的数据库,然后首先使用数据库将其反射(reflect)到实体模型中。所以我现在已经有了让我们说 myOwnDBContext。
然后我认为将它与 IdentityDbContext 生成的类混合是个好主意。但是当我像这样更改 IdentityModel 中的连接字符串时

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("myOwnDBConnectionString")
{
}
}

这些表没有按照我在 myOwnDB 中的预期生成,而是收到以下错误。

The entity type ApplicationUser is not part of the model for the current context.



有没有办法可以将 IdentityDbContext 的默认数据库与我自己的数据库混合?

最佳答案

我不确定这是否可以在不使用 EF 迁移的情况下工作,但我确实可以使用迁移。具体来说,两个 DbContext 派生类(一个用于自定义实体,一个从 IdentityDbContext 派生)。

对于迁移,我必须从包管理器控制台为两个上下文启用迁移,并使用 -MigrationsDirectory 参数将两组迁移放入不同的文件夹(EF6 的一项新功能)。

然后在运行 update-database 时,会为每个上下文正确创建表。 update-database 命令需要一个 -ConfigurationTypeName 参数来指定要使用的确切迁移。

关于asp.net-mvc - 您自定义数据库 IdentityDbContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19784233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com