public List <SelfReference> GetAllReferences() { using (var context = new ModelSelfReferences()) { return(context.SelfReferences.ToList()); } }
public void AddReference(SelfReference selfReference) { using (var context = new ModelSelfReferences()) { context.SelfReferences.Add(selfReference); context.SaveChanges(); } }
public static void Ex1() { using (var context = new ModelSelfReferences()) { var first = context.AddSelfReference("First"); context.AddSelfReference("WithRef", first); context.AddSelfReference("WithRef2", first); context.AddSelfReference("WithRef3", first); } using (var context = new ModelSelfReferences()) { foreach (var selfRef in context.SelfReferences) { Console.WriteLine("{0} {1} {2} {3}", selfRef.Name, selfRef.SelfReferenceId, selfRef.ParentSelfReferenceId, selfRef.ParentSelfReference.Name); } } }
private static void Problema1() { using (var context = new ModelSelfReferences()) { Console.Write("Enter Name:"); SelfReference p = new SelfReference() { Name = Console.ReadLine().ToString() }; context.SelfReferences.Add(p); context.SaveChanges(); var items = context.SelfReferences; foreach (var x in items) { Console.WriteLine(x.Name); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
static void firstPart() { using (ModelSelfReferences context = new ModelSelfReferences()) { SelfReference selfReference1 = new SelfReference() { Name = "Parinte" }; SelfReference selfReference2 = new SelfReference() { Name = "Copil1", ParentSelfReference = selfReference1 }; SelfReference selfReference3 = new SelfReference() { Name = "Copil2", ParentSelfReference = selfReference2 }; context.SelfReferences.Add(selfReference1); context.SelfReferences.Add(selfReference2); context.SelfReferences.Add(selfReference3); context.SaveChanges(); foreach (SelfReference self in context.SelfReferences) { Console.WriteLine("{0}, {1}", self.Name, self.ParentSelfReferenceId); foreach (SelfReference child in context.SelfReferences) { Console.WriteLine("Hashmap: {0}", child.Name); } } } Console.ReadKey(); }