如何共享DbContext而不获取2个用户表

问题描述 投票:0回答:1

我正在使用带有实体框架,Asp.Net身份和IdentityServer4的Asp.Net Core 3.1。我正在尝试在多个项目中共享我的DbContext,但是我的代码优先迁移并不能满足我的需求。代码优先迁移有可能吗?我的设置是否完全精简?谢谢您的时间。


我的带有DbContexts的项目层次结构。

Project Heirarchy

我想要的

Entity Relationship Goal

我得到的

Entity Relationship Actual

在身份和应用程序启动中都>
services.AddIdentity<AppUser, IdentityRole>()
        .AddEntityFrameworkStores<AppUserContext>()
        .AddDefaultTokenProviders();
...
services.AddDbContext<AppUserContext>(options => options.UseSqlServer(connectionString));

迁移
dotnet-ef migrations add Init -p User\User.csproj -c AppUserContext -s IdentityServer\IdentityServer.csproj
dotnet-ef migrations add Init -p Persistence\Persistence.csproj -c RecipeContext -s Application\Application.csproj


更新1

将AppUser和AppUserContext移动到IdentityServer。红色是受限制的端点。

Update 1 Sequence

我正在使用带有实体框架,Asp.Net身份和IdentityServer4的Asp.Net Core 3.1。我正在尝试在多个项目中共享我的DbContext,但是我的代码优先迁移并未产生我所想要的...

entity-framework asp.net-core ef-code-first identityserver4 asp.net-core-identity
1个回答
0
投票

感谢@RuardvanElburg的建议,我通过更改我的范式来“解决”了这个问题,您可以在我的Update 1

© www.soinside.com 2019 - 2024. All rights reserved.