I'm having to make a relationship between N: N classes but storing objects in memory, follows the following relationship:
Imadetheimplementationasfollowsandwouldliketoknowifitiscorrectornot.
ChemicalClass
publicclassChemical{publicintID{get;set;}publicstringChemicalName{get;set;}publicstringChemicalFormula{get;set;}publicDecimalMW{get;set;}publicintVFId{get;set;}//Visual_Flow_IDpublicBooleanProjectChemical{get;set;}publicChemical(){}
StreamClass
publicclassStream{publicintID{get;set;}publicstringName{get;set;}publicvirtualIList<StreamComposition>Chemicals{get;set;}publicStream(){this.Chemicals=newList<StreamComposition>();}publicvoidAddChemical(StreamCompositionsc){this.Chemicals.Add(sc);Console.WriteLine("Adding Chemical: " + sc.Chemical.ChemicalName +
" to the Stream: => " + sc.Stream.Name + "\n");
}
}
StreamComposition class
public class StreamComposition
{
public virtual Stream Stream { get; set; }
public virtual Chemical Chemical { get; set; }
public Decimal MolePerCent { get; set; }
public StreamComposition()
{
}
}
Populating objects
Creating Stream
Stream Stream1 = new Stream() { ID = 1, Name = "SHD4", };
Creation of the 3 objects 'Chemicals'
Chemical ch1 = new Chemical() // Criando uma 'Chemical'
{
ID = 1,
ChemicalName = "Hidrogenio",
ChemicalFormula = "H",
MW = 2,
VFId = 2,
ProjectChemical = true
};
Chemical ch2 = new Chemical() // Criando outra 'Chemical'
{
ID = 2,
ChemicalName = "Ferro",
ChemicalFormula = "Fe",
MW = 4,
VFId = 8,
ProjectChemical = false,
};
Chemical ch3 = new Chemical()
{
ID = 3,
ChemicalName = "Agua",
ChemicalFormula = "H20",
MW = 9,
VFId = 10,
ProjectChemical = true,
};
Creating the 3 associative classes
StreamComposition sc1 = new StreamComposition() // Criando StreamComposition
{
Stream = Stream1,
Chemical = ch1,
MolePerCent = 4.0m,
};
StreamComposition sc2 = new StreamComposition() // Criando StreamComposition
{
Stream = Stream1,
Chemical = ch2,
MolePerCent = 8.0m,
};
StreamComposition sc3 = new StreamComposition() // Criando StreamComposition
{
Stream = Stream1,
Chemical = ch3,
MolePerCent = 8.0m,
};
Assigning the Chemicals Created for the Stream 'Stream1'
Stream1.AddChemical(sc1);
Stream1.AddChemical(sc2);
Stream1.AddChemical(sc3);