有一个Blazor WebAssembly应用程序,在.Net 5.0.0中使用Asp.Net Core Hosting,它分为三个不同的项目:WebApp.Client
、WebApp.Server
、WebApp.Shared
。
我使用AspNetCore.Identity
和IdentityServer4
来管理我的应用程序用户。
但是类ApplicationUser : IdentityUser
在WebApp.Server
项目中,而我的模型类Foo
在WebApp.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; }
}