protected override void OnSetUp()
        {
            using (var session = OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    var parent = new EntityComplex
                    {
                        Name          = "ComplexEnityParent",
                        LazyProp      = "SomeBigValue",
                        SameTypeChild = new EntityComplex()
                        {
                            Name = "ComplexEntityChild"
                        },
                        SameTypeChild2 = new EntityComplex()
                        {
                            Name = "ComplexEntityChild2"
                        }
                    };

                    _entityWithCompositeId = new EntityWithCompositeId
                    {
                        Key = new CompositeKey
                        {
                            Id1 = 1,
                            Id2 = 2
                        },
                        Name = "Composite"
                    };

                    session.Save(parent.SameTypeChild);
                    session.Save(parent.SameTypeChild2);
                    session.Save(parent);
                    session.Save(_entityWithCompositeId);

                    _entityWithCustomEntityName = new EntityCustomEntityName()
                    {
                        Name = "EntityCustomEntityName"
                    };

                    session.Save(_customEntityName, _entityWithCustomEntityName);

                    _noAssociation = new EntityWithNoAssociation()
                    {
                        Complex1Id         = parent.Id,
                        Complex2Id         = parent.SameTypeChild.Id,
                        Composite1Key1     = _entityWithCompositeId.Key.Id1,
                        Composite1Key2     = _entityWithCompositeId.Key.Id2,
                        CustomEntityNameId = _entityWithCustomEntityName.Id
                    };

                    session.Save(_noAssociation);

                    session.Flush();
                    transaction.Commit();
                }
        }
Exemplo n.º 2
0
        public void EntityJoinForCustomEntityName()
        {
            using (var sqlLog = new SqlLogSpy())
                using (var session = OpenSession())
                {
                    EntityCustomEntityName ejCustomEntity = session.CreateQuery(
                        $"select ejCustomEntity from EntityWithNoAssociation root inner join {_customEntityName} ejCustomEntity with ejCustomEntity.Id = root.CustomEntityNameId")
                                                            .SetMaxResults(1).UniqueResult <EntityCustomEntityName>();

                    Assert.That(ejCustomEntity, Is.Not.Null);
                    Assert.That(NHibernateUtil.IsInitialized(ejCustomEntity), Is.True);
                    Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
                }
        }