so as an example lets say we have the following situation: I have a class called StandardEngineeredModel which has properties like ModelNumber, VoltageInput, VoltageOutput etc.
I also have a class called Fuse that has properties like Designator, Rating, and Type. In my database model these two classes would have a many to many relationship with eachother, a StandardEngineeredModel can contain MANY fuses, and a fuse can be contained in MANY different StandardEngineeredModels. See code below.
public class StandardEngineeredModel
{
StandardEngineeredModel()
{
Fuses = new List<Fuse>();
}
[Key]
public string ModelNumber { get; set; }
public int VoltageInput { get; set; }
public string VoltageOutput {get;set;}
public ICollection<Fuse> Fuses { get; set; }
}
public class Fuse
{
[Key,Column(Order = 0)]
public string Designator { get; set; }
[Key, Column(Order = 1)]
public string Rating { get; set; }
[Key, Column(Order = 2)]
public string Type { get; set; }
public ICollection<StandardEngineeredModel> StandardEngineeredModels { get; set; }
}
So my question is the portion where you initialize the collection in the constructor: For my StandardEngineeredModel it makes sense to initialize the Fuses with a list. But in my Fuse class it doesn't really make sense for me to initialize the ICollection because typically I will assign fuses to a StandardEngineeredModel not assign a StandardEngineeredModel to a fuse.
Is there any issue with doing this that I am not seeing? What types of problems can this cause for me down the road? I have used EF in a few of my applications but have yet to need a Many to Many relationship so I am looking for some general advice over this.
Thanks in advance!