コード例 #1
0
ファイル: Fixture.cs プロジェクト: jeynnecool/nhibernate-core
        public void ExpandSubCollectionWithEmbeddedCompositeID()
        {
            using (ISession s = OpenSession())
            using (var tx = s.BeginTransaction())
            {

	            var jenny = new Mum {Name = "Jenny"};
	            s.Save(jenny);
	            var benny = new Dad {Name = "Benny"};
	            s.Save(benny);
	            var lenny = new Dad {Name = "Lenny"};
	            s.Save(lenny);
	            var jimmy = new Kid {Name = "Jimmy", MumId = jenny.Id, DadId = benny.Id};
	            s.Save(jimmy);
	            var timmy = new Kid {Name = "Timmy", MumId = jenny.Id, DadId = lenny.Id};
	            s.Save(timmy);

	            tx.Commit();
            }

	        using (var s = OpenSession())
            {
                var result=s.Query<Mum>().Select(x => new { x, x.Kids }).ToList();
                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result[0].x.Kids, Is.EquivalentTo(result[0].Kids));
            }
        }
コード例 #2
0
        public async Task ExpandSubCollectionWithEmbeddedCompositeIDAsync()
        {
            using (ISession s = OpenSession())
                using (var tx = s.BeginTransaction())
                {
                    var jenny = new Mum {
                        Name = "Jenny"
                    };
                    await(s.SaveAsync(jenny));
                    var benny = new Dad {
                        Name = "Benny"
                    };
                    await(s.SaveAsync(benny));
                    var lenny = new Dad {
                        Name = "Lenny"
                    };
                    await(s.SaveAsync(lenny));
                    var jimmy = new Kid {
                        Name = "Jimmy", MumId = jenny.Id, DadId = benny.Id
                    };
                    await(s.SaveAsync(jimmy));
                    var timmy = new Kid {
                        Name = "Timmy", MumId = jenny.Id, DadId = lenny.Id
                    };
                    await(s.SaveAsync(timmy));

                    await(tx.CommitAsync());
                }

            using (var s = OpenSession())
            {
                var result = await(s.Query <Mum>().Select(x => new { x, x.Kids }).ToListAsync());
                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result[0].x.Kids, Is.EquivalentTo(result[0].Kids));
            }
        }