Пример #1
0
        public void ConfigureForCount(NpgsqlCommand command)
        {
            var sql = "select count(*) as number from " + _mapping.TableName + " as d";

            var where = buildWhereClause();

            sql = appendLateralJoin(sql);
            if (@where != null) sql += " where " + @where.ToSql(command);

            command.AppendQuery(sql);

        }
Пример #2
0
        public void ConfigureCommand(NpgsqlCommand command)
        {
            if (_query.ResultOperators.OfType<LastResultOperator>().Any())
            {
                throw new InvalidOperationException("Marten does not support the Last() or LastOrDefault() operations. Use a combination of ordering and First/FirstOrDefault() instead");
            }

            var select = _mapping.SelectFields("d");
            var sql = $"select {select} from {_mapping.TableName} as d";

            var where = buildWhereClause();
            var orderBy = toOrderClause();

            sql = appendLateralJoin(sql);
            if (@where != null) sql += " where " + @where.ToSql(command);

            if (orderBy.IsNotEmpty()) sql += orderBy;

            sql = appendLimit(sql);
            sql = appendOffset(sql);

            command.AppendQuery(sql);
        }