Exemple #1
0
 public void AddAChild()
 {
     Person john;
     Child johnJunior;
     using (var session = OpenSession())
     {
         john = session.Get<Person>(nicePersonId);
         Assert.IsNull(john.Partner);
         johnJunior = new Child("John Junior",john) {NickName = "John's FirstBorn"};
         john.AddChild(johnJunior);
         session.Flush();
         session.Clear();
     }
     using (var session = OpenSession())
     {
         john = session.Get<Person>(john.Id);
         Assert.IsTrue(john.Children.Where(x => x.Id == johnJunior.Id).Count() > 0);
     }
 }
Exemple #2
0
 public Toy(Child owner)
     : this()
 {
     this.owner = owner;
 }
Exemple #3
0
        public void ChangeTheNameOfTheCatFromSmellyToUgly()
        {
            Cat smellyCat;
            using (var session = OpenSession())
            {
                var john = session.Get<Person>(nicePersonId);
                john.AddCat(new Cat(john) { Name = "Whisky" });

                var johnJunior = new Child("John Junior",john) { NickName = "John's FirstBorn" };
                john.AddChild(johnJunior);

                smellyCat = new Cat(johnJunior) {Name = "Smelly Cat"};
                johnJunior.AddCat(smellyCat);

                session.Flush();
                session.Clear();
            }

            using (var session = OpenSession())
            {
                smellyCat = session.Get<Cat>(smellyCat.Id);
                smellyCat.Name = "Ugly cat";
                session.Flush();               //if you change the PreUpdateEventListenerImpl to Log.Info on the Master.Name you get an exception
            }
        }
Exemple #4
0
        public void ChangeTheNameOfTheNewtoyToBoringToy()
        {
            Toy newToy;
            using (var session = OpenSession())
            {
                var john = session.Get<Person>(nicePersonId);
                var johnJunior = new Child("John Junior", john) { NickName = "John's FirstBorn" };
                john.AddChild(johnJunior);

                newToy = new Toy(johnJunior) { Name = "New Toy Of The Day" };
                johnJunior.AddToy(newToy);

                session.Flush();
                session.Clear();
            }

            using (var session = OpenSession())
            {
                newToy = session.Get<Toy>(newToy.Id);
                newToy.Name = "Boring toy";
                session.Flush();
            }
        }
Exemple #5
0
 public virtual void AddChild(Child child)
 {
     children.Add(child);
     if(Partner != null)
         Partner.AddChild(child);
 }