简体   繁体   English

如何在EF Core中将桥接表拆分为两个表

[英]How to split bridge table into two tables in EF core

I have a requirement where I have slip the bridge table into tables for storing more info about the many to many relationship. 我有一个要求,我要将桥接表滑入表中,以存储有关多对多关系的更多信息。 So "idea" is that the ComputerUser table becomes two tables and reference that way so that more info can be stored in of these two bridge tables other than just many to many relationship references. 因此,“想法”是ComputerUser表成为两个表并以此方式进行引用,以便可以将更多信息存储在这两个桥表中,而不仅仅是多对多关系引用。 Thank you for your insights Following is what I have so : 谢谢您的见解以下是我的见解:

public  class Computer
{

[Key]
    public Guid ComputerId { get; set; }
    public string MachineName { get; set; }
    public DateTime Updated { get; set; }
    public string ClientVersion { get; set; }
    public DateTime LastActivity { get; set; }
    public string Secret { get; set; }
    public Setting Settings { get; set; }
    public bool IsActive { get; set; } 
    public bool? ResetRequested { get; set; } 
    public ICollection<ScanEvent> Scans { get; set; }
    public ICollection<EventLog> Logs { get; set; }
    public ICollection<ComputerUser> UserLinks { get; set; }
    }
public class ComputerUser
{
    [Key,Column(Order = 1)]
    public Guid ComputerId { get; set; }
    public  Computer Computer { get; set; }
    [Key, Column(Order = 2)]
    public Guid  UserId { get; set; }
    public  User User { get; set; }

}

    public class User
 {
    [Key]

   public Guid   UserId { get; set; } 
   public  string Name { get; set; }
   public bool IsActive { get; set; } = true;
   public DateTime Updated { get; set; } 
   public Setting Setting { get; set; } 
   public long SerialNumber { get; set; } 
   public virtual ICollection<Device> Devices { get; set; }
   public virtual ICollection<Credential> Credentials { get; set; }
   public virtual ICollection<ComputerUser> ComputerLinks { get; set; }
   }

All you're talking about is a M2M with a payload (ie additional information besides just the relationship itself). 您正在谈论的是带有有效负载的M2M(即,除了关系本身之外的其他信息)。 The only requirement for that is a using an actual entity class for your relationship, which you're already doing with ComputerUser . 唯一的要求是为您的关系使用实际的实体类,您已经在使用ComputerUser Simply add additional properties as necessary to that entity. 只需根据需要向该实体添加其他属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM