表示 Entity Framework 中的交汇点 Table

Representing a Junction Table in Entity Framework

我正在创建一个应用以下逻辑的模式:

基本上,我已经使用连接 table 将关系映射为 多对多 关系,如下所示:

在映射 Code First EF6 中的图表(使用 SQLite)时,我有以下对象:

public class Location
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long LocationId { get; set; }

    [Required]
    public string Country { get; set; }

    [Required]
    public string CityOrProvince { get; set; }

    [Required]
    public string PlaceOrCity { get; set; }

    [Required]
    public string PostalCode { get; set; }
}

public class String
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long StringId { get; set; }

    [Required]
    public string SearchString { get; set; }
}

public class LocationStringMapping
{
    [Required]
    public string LocationId { get; set; }

    [Required]
    public string StringId { get; set; }

    [Required]
    public DateTime DateScraped { get; set; }
}

到目前为止,我所做的一切都是基于推测,因为我似乎找不到任何关于必须如何建立这种关系的具体信息。通常我会使用 junction table,但那是原版的 SQL。 EF 中的实现是否不同?

我是否需要手动繁琐地管理 LocationStringMapping table 还是存在某种我不知道的隐式关系模型?

public class Location
{
    public long LocationId {get;set;}
    public virtual ICollection<LocationStringMapping> LocationStringMappings {get;set;}
    //other
}

public class String
{
    public long StringId {get;set;}
    public virtual ICollection<LocationStringMapping> LocationStringMappings {get;set;}
    //other
}

public class LocationStringMapping
{
    [Key, Column(Order = 0)]
    public long LocationId { get; set; }
    [Key, Column(Order = 1)]
    public long StringId { get; set; }

    public virtual Location Location {get;set;}
    public virtual String String {get;set;}

    public DateTime DateScraped {get;set;}
}