public static void TestScenariu1() { ModelSelfRefrences context = new ModelSelfRefrences(); SelfReference referinta1 = new SelfReference() { Name = "Referinta1" }; SelfReference referinta2 = new SelfReference() { Name = "Referinta2", ParentSelfReference = referinta1 }; referinta1.References.Add(referinta2); SelfReference referinta3 = new SelfReference() { Name = "Referinta3", ParentSelfReference = referinta2 }; referinta2.References.Add(referinta3); SelfReference referinta4 = new SelfReference() { Name = "Referinta4", ParentSelfReference = referinta2 }; referinta2.References.Add(referinta4); context.SelfReferences.Add(referinta1); context.SelfReferences.Add(referinta2); context.SelfReferences.Add(referinta3); context.SelfReferences.Add(referinta4); context.SaveChanges(); }
public static void AfisareScenariu1() { ModelSelfRefrences context = new ModelSelfRefrences(); foreach (var reference in context.SelfReferences.ToList()) { Console.WriteLine($"Referinta:{reference.Name} NumeParinte:{(reference.ParentSelfReference != null ? reference.ParentSelfReference.Name : "None")}"); } }