Exemple #1
0
        static void ScenariuUnu()
        {
            var scenarioOne = new ScenariuUnu();
            var refUnu      = new SelfReference();

            refUnu.Name = "Prima referinta";
            scenarioOne.AddReference(refUnu);

            var refDoi = new SelfReference();

            refDoi.Name = "A doua referinta";
            refDoi.ParentSelfReference = refUnu;
            scenarioOne.AddReference(refDoi);

            var refTrei = new SelfReference();

            refTrei.Name = "A treia referinta";
            refTrei.ParentSelfReference = refDoi;
            scenarioOne.AddReference(refTrei);

            foreach (var reference in scenarioOne.GetAllReferences())
            {
                if (reference.ParentSelfReference != null)
                {
                    Console.WriteLine($"Reference {reference.Name} with parent {reference.ParentSelfReference.Name}");
                }
            }
        }
Exemple #2
0
 public void AddReference(SelfReference selfReference)
 {
     using (var context = new ModelSelfReferences())
     {
         context.SelfReferences.Add(selfReference);
         context.SaveChanges();
     }
 }
Exemple #3
0
        public SelfReference AddSelfReference(string name)
        {
            var selfReference = new SelfReference()
            {
                Name = name,
            };

            SelfReferences.Add(selfReference);
            SaveChanges();
            return(selfReference);
        }
        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();
            }
        }
Exemple #5
0
        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();
        }