Example #1
0
 public virtual void UnbindFromCurrentOwner()
 {
     if (owner != null)
     {
         owner.AssociatedEntities.Remove(this);
         owner = null;
     }
 }
		public virtual void UnbindFromCurrentOwner()
		{
			if (owner != null)
			{
				owner.AssociatedEntities.Remove(this);
				owner = null;
			}
		}
Example #3
0
 public virtual void BindToOwner(SimpleEntityWithAssociation owner)
 {
     if (owner != this.owner)
     {
         UnbindFromCurrentOwner();
     }
     this.owner = owner;
     if (owner != null)
     {
         owner.AssociatedEntities.Add(this);
     }
 }
		public virtual void BindToOwner(SimpleEntityWithAssociation owner)
		{
			if (owner != this.owner)
			{
				UnbindFromCurrentOwner();
			}
			this.owner = owner;
			if (owner != null)
			{
				owner.AssociatedEntities.Add(this);
			}
		}
Example #5
0
        protected override void OnSetUp()
        {
            using (var s = OpenSession())
                using (var txn = s.BeginTransaction())
                {
                    _polliwog = new Animal {
                        BodyWeight = 12, Description = "Polliwog"
                    };
                    _catepillar = new Animal {
                        BodyWeight = 10, Description = "Catepillar"
                    };
                    _frog = new Animal {
                        BodyWeight = 34, Description = "Frog"
                    };
                    _butterfly = new Animal {
                        BodyWeight = 9, Description = "Butterfly"
                    };

                    _polliwog.Father = _frog;
                    _frog.AddOffspring(_polliwog);
                    _catepillar.Mother = _butterfly;
                    _butterfly.AddOffspring(_catepillar);

                    s.Save(_frog);
                    s.Save(_polliwog);
                    s.Save(_butterfly);
                    s.Save(_catepillar);

                    var dog = new Dog {
                        BodyWeight = 200, Description = "dog"
                    };
                    s.Save(dog);
                    var cat = new Cat {
                        BodyWeight = 100, Description = "cat"
                    };
                    s.Save(cat);

                    var dragon = new Dragon();
                    dragon.SetFireTemperature(200);
                    s.Save(dragon);

                    _zoo = new Zoo {
                        Name = "Zoo"
                    };
                    var add = new Address {
                        City = "MEL", Country = "AU", Street = "Main st", PostalCode = "3000"
                    };
                    _zoo.Address = add;

                    _pettingZoo = new PettingZoo {
                        Name = "Petting Zoo"
                    };
                    var addr = new Address {
                        City = "Sydney", Country = "AU", Street = "High st", PostalCode = "2000"
                    };
                    _pettingZoo.Address = addr;

                    s.Save(_zoo);
                    s.Save(_pettingZoo);

                    var joiner = new Joiner {
                        JoinedName = "joined-name", Name = "name"
                    };
                    s.Save(joiner);

                    var car = new Car {
                        Vin = "123c", Owner = "Kirsten"
                    };
                    s.Save(car);
                    var truck = new Truck {
                        Vin = "123t", Owner = "Steve"
                    };
                    s.Save(truck);
                    var suv = new SUV {
                        Vin = "123s", Owner = "Joe"
                    };
                    s.Save(suv);
                    var pickup = new Pickup {
                        Vin = "123p", Owner = "Cecelia"
                    };
                    s.Save(pickup);

                    var entCompKey = new EntityWithCrazyCompositeKey {
                        Id = new CrazyCompositeKey {
                            Id = 1, OtherId = 1
                        }, Name = "Parent"
                    };
                    s.Save(entCompKey);

                    _joe = new Human {
                        Name = new Name {
                            First = "Joe", Initial = 'Q', Last = "Public"
                        }
                    };
                    _doll = new Human {
                        Name = new Name {
                            First = "Kyu", Initial = 'P', Last = "Doll"
                        }, Friends = new[] { _joe }
                    };
                    _stevee = new Human {
                        Name = new Name {
                            First = "Stevee", Initial = 'X', Last = "Ebersole"
                        }
                    };
                    s.Save(_joe);
                    s.Save(_doll);
                    s.Save(_stevee);

                    _intVersioned = new IntegerVersioned {
                        Name = "int-vers", Data = "foo"
                    };
                    s.Save(_intVersioned);

                    _timeVersioned = new TimestampVersioned {
                        Name = "ts-vers", Data = "foo"
                    };
                    s.Save(_timeVersioned);

                    var scwc = new SimpleClassWithComponent {
                        Name = new Name {
                            First = "Stevee", Initial = 'X', Last = "Ebersole"
                        }
                    };
                    s.Save(scwc);

                    var mainEntWithAssoc = new SimpleEntityWithAssociation()
                    {
                        Name = "main"
                    };
                    var otherEntWithAssoc = new SimpleEntityWithAssociation()
                    {
                        Name = "many-to-many-association"
                    };
                    mainEntWithAssoc.ManyToManyAssociatedEntities.Add(otherEntWithAssoc);
                    mainEntWithAssoc.AddAssociation("one-to-many-association");
                    s.Save(mainEntWithAssoc);

                    var owner = new SimpleEntityWithAssociation {
                        Name = "myEntity-1"
                    };
                    owner.AddAssociation("assoc-1");
                    owner.AddAssociation("assoc-2");
                    owner.AddAssociation("assoc-3");
                    s.Save(owner);
                    var owner2 = new SimpleEntityWithAssociation {
                        Name = "myEntity-2"
                    };
                    owner2.AddAssociation("assoc-1");
                    owner2.AddAssociation("assoc-2");
                    owner2.AddAssociation("assoc-3");
                    owner2.AddAssociation("assoc-4");
                    s.Save(owner2);
                    var owner3 = new SimpleEntityWithAssociation {
                        Name = "myEntity-3"
                    };
                    s.Save(owner3);

                    txn.Commit();
                }
        }