Ejemplo n.º 1
0
        private static void AddSelfReference()
        {
            SelfReference self = new SelfReference()
            {
                Name       = "Andrei",
                References = new List <SelfReference>()
                {
                    new SelfReference()
                    {
                        Name       = "Ion",
                        References = new List <SelfReference>()
                        {
                            new SelfReference()
                            {
                                Name = "Geri"
                            },
                        }
                    },
                    new SelfReference()
                    {
                        Name = "Vasile"
                    }
                }
            };

            using var context = new ModelSelfReferences();
            context.SelfReferences.Add(self);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        static void TestSelfReferences()
        {
            using (ModelSelfReferences context = new ModelSelfReferences())
            {
                SelfReference s1 = new SelfReference()
                {
                    Name = "Reference A"
                };
                SelfReference s2 = new SelfReference()
                {
                    Name = "Reference B"
                };

                s2.References.Add(s1);
                context.SelfReferences.Add(s1);
                context.SelfReferences.Add(s2);
                context.SaveChanges();

                foreach (var sr in context.SelfReferences)
                {
                    Console.WriteLine("{0}, {1}", sr.SelfReferenceId, sr.Name);
                    if (sr.References != null)
                    {
                        foreach (var SR in sr.References)
                        {
                            Console.WriteLine("{0}, {1}", SR.SelfReferenceId, SR.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private static void TestSelfReference()
 {
     AddSelfReference();
     using var context = new ModelSelfReferences();
     foreach (var x in context.SelfReferences.Include("References"))
     {
         Console.WriteLine("Name: " + x.Name);
         if (x.References.Count > 0)
         {
             foreach (var reference in x.References)
             {
                 Console.WriteLine("--->referinta catre: " + reference.Name);
             }
         }
     }
 }