我目前有EF核心代码,对以下ER建模:
我想添加一个关系属性,如下所示:
以下是当前代码的相关部分:
public class System
{
public string SystemId { get; set; }
public List<Component> Components { get; set; } = new List<Component>();
}
public class Component
{
public int ComponentId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
----
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<System>()
.HasMany(s => s.Components)
.WithMany();
}
这段代码在数据库中构建了一个查找表,将两个实体链接起来.就像这样:
对于我想要实现的更改,我希望在查找表中有一个新的列(即版本),但我找不到任何方法来实现它.
我已try 按如下方式更改代码:
public class System
{
public string SystemId { get; set; }
public List<ComponentRelationship> Components { get; set; } = new List<ComponentRelationship>();
}
public class ComponentRelationship
{
public int Id { get; set; }
public Component Component { get; set; }
public string Version { get; set; }
}
但它并没有真正做到我想要的.
有哪些方法可以创建关系属性?