static void Main(string[] args) { Morph M1 = new Morph() { MorphID = 1, het = false, MorphName = "M1" }; Morph M2 = new Morph() { MorphID = 2, het = false, MorphName = "M2" }; Morph M3prime = new Morph() { MorphID = 3, het = true, MorphName = "M3" }; Morph M4prime = new Morph() { MorphID = 4, het = true, MorphName = "M4" }; Morph Mfour = new Morph() { MorphID = 7, het = false, MorphName = "M4" }; Morph Mfive = new Morph() { MorphID = 8, het = false, MorphName = "M5" }; Morph Mfiveprime = new Morph() { MorphID = 9, het = true, MorphName = "M5" }; Lizard L1 = new Lizard() { LizardID = 1, Name = "Liz 1" }; Lizard L2 = new Lizard() { LizardID = 2, Name = "Liz 2" }; L1.Morphs = new List <Morph>() { M1, M2, M3prime, M4prime }; L2.Morphs = new List <Morph>() { M1, M3prime, Mfour, Mfiveprime }; var total = Compute(L1, L2); foreach (var x in total) { Console.WriteLine(x); } }
static List <MorphPlus> Compute(Lizard One, Lizard two) { var leftouter = (from m1 in One.Morphs join m2 in two.Morphs on m1.MorphName equals m2.MorphName //select new MorphPlus(m1, m2); into loj from mempty in loj.DefaultIfEmpty() select new MorphPlus(m1, loj.FirstOrDefault())).ToList(); var rightouter = (from m1 in two.Morphs join m2 in One.Morphs on m1.MorphName equals m2.MorphName into loj from mempty in loj.DefaultIfEmpty() select new MorphPlus(m1, loj.FirstOrDefault())).ToList(); return((leftouter.Union(rightouter)).ToList()); }