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();
                }
        }
Example #2
0
        public void entity_with_composite_id_can_be_persisted_and_retreieved()
        {
            var entityWithCompositeId = new EntityWithCompositeId(new CompositeId(23, "string id"));

            UnitOfWork.Save <EntityWithCompositeId, CompositeId>(entityWithCompositeId);
            UnitOfWork.Clear();

            var fetchedEntityWithCompositeId = UnitOfWork.Get <EntityWithCompositeId, CompositeId>(entityWithCompositeId.Id);

            (fetchedEntityWithCompositeId == entityWithCompositeId).ShouldBeTrue();
            (fetchedEntityWithCompositeId.Id.IdOne == entityWithCompositeId.Id.IdOne).ShouldBeTrue();
            (fetchedEntityWithCompositeId.Id.IdTwo == entityWithCompositeId.Id.IdTwo).ShouldBeTrue();
        }
        public void OneToOneCompositeQueryOverCompareWithJoin()
        {
            using (new SqlLogSpy())
                using (var session = OpenSession())
                {
                    Parent parent = null;
                    EntityWithCompositeId oneToOne = null;

                    var loadedEntity = session.QueryOver <Parent>(() => parent)
                                       .JoinEntityAlias(() => oneToOne, () => parent.OneToOneComp == oneToOne)
                                       .SingleOrDefault();

                    Assert.That(loadedEntity, Is.Not.Null);
                }
        }
        public void OneToOneCompositeQueryOverCompareWithJoinById()
        {
            using (var session = OpenSession())
            {
                var    e      = session.Query <EntityWithCompositeId>().FirstOrDefault();
                Parent parent = null;
                EntityWithCompositeId oneToOne = null;

                var loadedEntity = session.QueryOver <Parent>(() => parent)
                                   .JoinEntityAlias(() => oneToOne, () => parent.OneToOneComp.Key == oneToOne.Key)
                                   .SingleOrDefault();

                Assert.That(loadedEntity, Is.Not.Null);
            }
        }