コード例 #1
0
ファイル: Fixture.cs プロジェクト: jrauber/GH1429
        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();
                }
        }
コード例 #2
0
        public void JustForFun()
        {
            Configuration conf = ConfigureNHibernate();

            conf.AddDeserializedMapping(GetMapping(), "Animals_Domain");
            SchemaMetadataUpdater.QuoteTableAndColumns(conf);
            new SchemaExport(conf).Create(false, true);
            ISessionFactory factory = conf.BuildSessionFactory();

            using (ISession s = factory.OpenSession())
            {
                using (ITransaction tx = s.BeginTransaction())
                {
                    var polliwog = new Animal {
                        BodyWeight = 12, Description = "Polliwog"
                    };

                    var catepillar = new Animal {
                        BodyWeight = 10, Description = "Catepillar"
                    };

                    var frog = new Animal {
                        BodyWeight = 34, Description = "Frog"
                    };

                    polliwog.Father = frog;
                    frog.AddOffspring(polliwog);

                    var butterfly = new Animal {
                        BodyWeight = 9, Description = "Butterfly"
                    };

                    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 zoo = new Zoo {
                        Name = "Zoo"
                    };
                    var add = new Address {
                        City = "MEL", Country = "AU", Street = "Main st", PostalCode = "3000"
                    };
                    zoo.Address = add;

                    Zoo 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);
                    tx.Commit();
                }
            }

            using (ISession s = factory.OpenSession())
            {
                using (ITransaction tx = s.BeginTransaction())
                {
                    s.CreateQuery("delete from Animal where mother is not null or father is not null").ExecuteUpdate();
                    s.CreateQuery("delete from Animal").ExecuteUpdate();
                    s.CreateQuery("delete from Zoo").ExecuteUpdate();
                    tx.Commit();
                }
            }

            new SchemaExport(conf).Drop(false, true);
        }
コード例 #3
0
			public void Prepare()
			{
				ISession s = tc.OpenNewSession();
				ITransaction txn = s.BeginTransaction();

				Polliwog = new Animal {BodyWeight = 12, Description = "Polliwog"};

				Catepillar = new Animal {BodyWeight = 10, Description = "Catepillar"};

				Frog = new Animal {BodyWeight = 34, Description = "Frog"};

				Polliwog.Father = Frog;
				Frog.AddOffspring(Polliwog);

				Butterfly = new Animal {BodyWeight = 9, Description = "Butterfly"};

				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);

				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 b = new BooleanLiteralEntity();
				s.Save(b);

				txn.Commit();
				s.Close();
			}