来自单独数据库的实体框架核心外键

jle*_*man 5 c# relational-database asp.net-core-mvc asp.net-core-2.0 entity-framework-core-2.1

我是 EF Core 和数据库的新手,因为我还是一名学生。我在我正在制作的项目中要求有一个独立于应用程序数据库的身份数据库。

我已经使用 ASP.NET Core Identity 和一些自定义属性设置了身份数据库。我正在整理另一个数据库来存储联系页面的票证,但由于某种原因,我似乎无法使外键正常工作。当我迁移新数据库时,它会在我的应用程序数据库中为我已经在 Identity 数据库中自定义的 Identity 类创建一个重复表。

我想知道如何防止这种情况以及它是否与外键相关,因为我在网上找到的信息似乎表明 EF Core 2.1 不支持

模型中的标识类:

using Microsoft.AspNetCore.Identity;

namespace WebTemplate.Models
{
    public class Identity : IdentityUser
    {
        public string Building { get; set; }
        public string Room { get; set; }
        public string FullName { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

模型中的ContactForm类:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace WebTemplate.Models
{
    public enum StatusCode
    {
        [Display(Name="Open")]Open,
        [Display(Name = "Under Review")] UnderReview,
        [Display(Name = "Pending Change")] PendingChange,
        [Display(Name = "Closed-Resolved")] Resolved,
        [Display(Name = "Closed-No Action")] NoAction
    }

    public class ContactForm
    {
        [Key]
        public int ContactFormId { get; set; }
        public string SenderId { get; set; }
        [ForeignKey("SenderId")]
        public Identity Sender { get; set; }
        public string Subject { get; set; }
        public string Content { get; set; }
        public StatusCode Status { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

AppIdentityDbContext :

//removed for brevity
namespace WebTemplate.Models
{
    public class AppIdentityDbContext : IdentityDbContext<Identity>
    {
        public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options) : base(options) { }
        //Seed Data removed for brevity
    }
}
Run Code Online (Sandbox Code Playgroud)

应用数据库上下文

//removed for brevity
namespace WebTemplate.Models
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
        public DbSet<ContactForm> ContactForms { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)