I am struggling on how to map these two tables together, the Column TitleID
on the Name
table maps to the TitleID
on the Title
table. The table primary keys are NameTableID
/ TitleTableID
and are unique, NameID
, TitleID
(on both tables) are not unique, the current record is found by a null in the DateEnd
column.
public class Name
{
public int NameTableID { get; set; }
public int NameID { get; set; }
public int TitleID { get; set; } // Maps to Title.TitleID
public virtual Title Title { get; set; }
public string GivenName { get; set; }
public string FamilyName { get; set; }
public DateTime DateStart { get; set; }
public DateTime? DateEnd { get; set; }
}
public class Title
{
public int TitleTableID { get; set; }
public int TitleID { get; set; } // Maps to Name.TitleID
public string Description { get; set; }
public DateTime DateStart { get; set; }
public DateTime? DateEnd { get; set; }
}
I am assuming I need to add a bit of code to OnModelCreating
in my DB Context class, but am struggling with the mapping / code, any ideas?
Thanks, Martin