如何在EF Core中的单独项目之间向ApplicationUser添加外键



有一个Blazor WebAssembly应用程序,在.Net 5.0.0中使用Asp.Net Core Hosting,它分为三个不同的项目:WebApp.ClientWebApp.ServerWebApp.Shared

我使用AspNetCore.IdentityIdentityServer4来管理我的应用程序用户。

但是类ApplicationUser : IdentityUserWebApp.Server项目中,而我的模型类FooWebApp.Shared项目中。(WebApp.Server项目有WebApp.Shared项目的参考,所以Foo不能using WebApp.Server.Models。(

我可以在单独的项目之间向ApplicationUser类添加外键吗?或者我可以将ApplicationUser移到WebApp.Shared项目吗?

代码

// WebApp.Server.Models.ApplicationUser
public class ApplicationUser : IdentityUser
{
public virtual List<Foo> Foos { get; set; }
}
// WebApp.Shard.Models.Foo
public class Foo
{
public int ApplicationUserId { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; } // CS0246 
}

没有许多依赖关系的方法是:

//WebApp.Shard.Models.Too

using System.ComponentModel.DataAnnotations.Schema;
public class Foo<TUser>
{
public int ApplicationUserId { get; set; }
[ForeignKey(nameof(ApplicationUserId))]
public virtual TUser ApplicationUser { get; set; }
}

最新更新