Exemplo n.º 1
0
        private Task <IList <T> > GetResultUsingProjectionAsync(IQueryOver <T, T> query, string[] fields = null, CancellationToken token = default(CancellationToken))
        {
            if (fields == null || fields.Length == 0)
            {
                return(query.ListAsync <T>(token));
            }

            var projectionList = Projections.ProjectionList()
                                 .Add(Projections.Id(), "Id");

            foreach (var prop in fields)
            {
                if (prop == "Id")
                {
                    continue;
                }

                projectionList.Add(Projections.Property(prop), prop);
            }
            var results = query.Select(projectionList)
                          .TransformUsing(Transformers.AliasToBean <T>())
                          .ListAsync <T>(token);

            return(results);
        }
Exemplo n.º 2
0
        public async Task CanUseExpressionForWhereAsync()
        {
            using (ISession session = Sfi.OpenSession())
            {
                IQueryOver <Item, Item> query = session.QueryOver(() => Item);

                var start = DateTime.UtcNow;

                query
                .Where(GetExpression(start));

                await(query.ListAsync());
            }
        }
Exemplo n.º 3
0
        public async Task CanOuterJoinMultipleTablesWithComplexWithClauseAsync()
        {
            using (ISession session = Sfi.OpenSession())
            {
                IQueryOver <Parent, Parent> query = session.QueryOver(() => RootElement);

                A A_Alias = null;
                B B_Alias = null;
                C C_Alias = null;
                query.Left.JoinQueryOver(parent => parent.C, () => C_Alias, c => c.PropC == A_Alias.PropA && c.PropC == B_Alias.PropB);
                query.Left.JoinQueryOver(parent => parent.A, () => A_Alias);
                query.Left.JoinQueryOver(parent => parent.B, () => B_Alias, b => b.PropB == A_Alias.PropA);
                // Expected join order: a --> b --> c

                // This query should not throw
                await(query.ListAsync());
            }
        }
Exemplo n.º 4
0
        public async Task RowCountAsync()
        {
            await(SetupPagingDataAsync());

            using (ISession s = OpenSession())
            {
                IQueryOver <Person> query =
                    s.QueryOver <Person>()
                    .JoinQueryOver(p => p.Children)
                    .OrderBy(c => c.Age).Desc
                    .Skip(2)
                    .Take(1);

                IList <Person> results     = await(query.ListAsync());
                int            rowCount    = await(query.RowCountAsync());
                object         bigRowCount = await(query.RowCountInt64Async());

                Assert.That(results.Count, Is.EqualTo(1));
                Assert.That(results[0].Name, Is.EqualTo("Name 3"));
                Assert.That(rowCount, Is.EqualTo(4));
                Assert.That(bigRowCount, Is.TypeOf <long>());
                Assert.That(bigRowCount, Is.EqualTo(4));
            }
        }
        public static async Task <ListaPaginada <object> > PaginadoObjectAsync <T>(this IQueryOver <T, T> query, int pagina, int tamanhoPagina) where T : class
        {
            IFutureValue <long> count = MontarQueryPaginado(query, pagina, tamanhoPagina);

            return(await Task.FromResult(new ListaPaginada <object>(await query.ListAsync <object>(), count.Value, tamanhoPagina)));
        }