Hallo I have a situation that I have a problem with:
I Have 3 models lets say Device, Inbox and Suffix. Device can have only one Inbox and Inbox can be assign to many devices And Inbox and Suffix are connected with many to many relationship by junction table.
fluent api for inbox(SectionName) and sugffix would look like:
modelBuilder.Entity<SectionName>()
.HasMany(suffix => suffix.SectionsSuffix)
.WithMany(name => name.SectionsName)
.Map(nameSuffix =>
{
nameSuffix.ToTable("SectionsNameSuffix");
nameSuffix.MapLeftKey("SectionNameId");
nameSuffix.MapRightKey("SectionSuffixId");
});
Models are nothing special:
Inbox:
[Table("SectionsName")]
public class SectionName : BaseEntity
{
public SectionName()
{
SectionsSuffix = new List<SectionSuffix>();
}
[Required]
public string Name { get; set; }
public ICollection<SectionSuffix> SectionsSuffix { get; set; }
}
Suffix:
[Table("SectionsSuffix")]
public class SectionSuffix : BaseEntity
{
public SectionSuffix()
{
SectionLines = new List<SectionLine>();
SectionsName = new List<SectionName>();
}
[Required]
public string Name { get; set; }
public ICollection<SectionLine> SectionLines { get; set; }
public ICollection<SectionName> SectionsName { get; set; }
}
And device:
public class Device
{
protected Device()
{
}
public int Id { get; set; }
public string Description { get; set; }
public int? InboxId { get; set; }
[ForeignKey("InboxId")]
public virtual SectionName Inbox { get; set; }
}
So basically one device can be connected to single combination of inbox and suffix
Suffix is connected to another many to many but that's just for information.
Now, I am looking for a way to when I get records from device entity will know witch combination is used. I was thinking about adding additional column to junction table, but would that complicate things, and I wonder if there is a another way to do it.