Ejemplo n.º 1
0
        public void CacheableCriteriaWithAliasedJoinFuture()
        {
            using (var session = OpenSession())
            {
                EntitySimpleChild child1 = null;
                var ecFuture             = session.QueryOver <EntityComplex>()
                                           .JoinAlias(c => c.Child1, () => child1)
                                           .Where(c => c.Id == _parentId)
                                           .Cacheable()
                                           .FutureValue();
                EntityComplex value = null;
                Assert.DoesNotThrow(() => value = ecFuture.Value);
                Assert.That(value, Is.Not.Null);
            }

            using (var sqlLog = new SqlLogSpy())
                using (var session = OpenSession())
                {
                    EntitySimpleChild child1 = null;
                    var ecFuture             = session.QueryOver <EntityComplex>()
                                               .JoinAlias(c => c.Child1, () => child1)
                                               .Where(c => c.Id == _parentId)
                                               .Cacheable()
                                               .FutureValue();
                    EntityComplex value = null;
                    Assert.DoesNotThrow(() => value = ecFuture.Value);
                    Assert.That(value, Is.Not.Null);

                    Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(0), "Query is expected to be retrieved from cache");
                }
        }
Ejemplo n.º 2
0
        protected override void OnSetUp()
        {
            using (var session = OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    var child1 = new EntitySimpleChild
                    {
                        Name = "Child1",
                    };
                    var child2 = new EntitySimpleChild
                    {
                        Name = "Child2"
                    };
                    var complex = new EntityComplex
                    {
                        Name          = "ComplexEnityParent",
                        Child1        = child1,
                        Child2        = child2,
                        LazyProp      = "SomeBigValue",
                        SameTypeChild = new EntityComplex()
                        {
                            Name = "ComplexEntityChild"
                        },
                    };
                    child1.Parent = child2.Parent = complex;

                    var eager = new EntityEager()
                    {
                        Name = "eager1",
                    };

                    var eager2 = new EntityEager()
                    {
                        Name = "eager2",
                    };
                    eager.ChildrenListSubselect = new List <EntitySubselectChild>()
                    {
                        new EntitySubselectChild()
                        {
                            Name   = "subselect1",
                            Parent = eager,
                        },
                        new EntitySubselectChild()
                        {
                            Name   = "subselect2",
                            Parent = eager,
                        },
                    };

                    session.Save(child1);
                    session.Save(child2);
                    session.Save(complex.SameTypeChild);
                    session.Save(complex);
                    session.Save(eager);
                    session.Save(eager2);

                    session.Flush();
                    transaction.Commit();

                    _parentId = complex.Id;
                    _eagerId  = eager.Id;
                }
        }