public static void Scenariu1AfisareDate() { using (var context = new ModelSelfReferences()) { foreach (var reference in context.SelfReferences) { if (reference.ParentSelfReference is null) { Console.WriteLine(reference.Name); foreach (var subreference in reference.References) { Console.Write(" "); Console.WriteLine(subreference.Name); } } } } }
public static void Scenariu1IncarcareDate() { using (var context = new ModelSelfReferences()) { var rootEntity = new SelfReference() { Name = "ProgrammingLanguages" }; context.SelfReferences.Add(rootEntity); var childEntity1 = new SelfReference() { Name = "C#", ParentSelfReference = rootEntity }; context.SelfReferences.Add(childEntity1); var childEntity2 = new SelfReference() { Name = "C++", ParentSelfReference = rootEntity }; context.SelfReferences.Add(childEntity2); context.SaveChanges(); } }