Esempio n. 1
0
        /// <summary>
        /// Appends the current column name in unqualified form, e.g. <c>"MyColumn"</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute ColName(this IProjectionAttribute attribute)
        {
            ITableMetadata column = ProjectionHelper.GetPreferredColumnMetadata(attribute);

            string identifier = attribute.Context.Domain.Dialect.Identifier(column.ColumnName);

            return(attribute.Append(identifier));
        }
Esempio n. 2
0
        /// <summary>
        /// Appends the current table alias, e.g. <c>T0</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute Ali(this IProjectionAttribute attribute)
        {
            ITableMetadata table = ProjectionHelper.GetTableMetadata(attribute);

            string alias = attribute.Context.Lookup.Table(attribute.Identity, table.Identity);

            return(attribute.Append(alias));
        }
Esempio n. 3
0
        /// <summary>
        /// Appends the current JSON path literal, e.g. <c>'$.my.value'</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute JsonPath(this IProjectionAttribute attribute)
        {
            IJsonMetadata metadata = ProjectionHelper.GetJsonMetadata(attribute.Metadata);

            string literal = attribute.Context.Domain.Dialect.String(metadata.Path);

            return(attribute.Append(literal));
        }
Esempio n. 4
0
        /// <summary>
        /// Appends the current table name, e.g. <c>"MyTable"</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute TblName(this IProjectionAttribute attribute)
        {
            ITableMetadata table = ProjectionHelper.GetTableMetadata(attribute);

            string qualifier = attribute.Context.Domain.Dialect.Qualifier;
            string tableName = string.Join(qualifier, table.TableName.Select(attribute.Context.Domain.Dialect.Identifier));

            return(attribute.Append(tableName));
        }
Esempio n. 5
0
        /// <summary>
        /// Appends the current variable name, e.g. <c>@V0</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute Var(this IProjectionAttribute attribute)
        {
            IField field = ProjectionHelper.GetFieldValue(attribute);

            string variableName = attribute.Context.Lookup.Variable(attribute.Identity, field);
            string dialectName  = attribute.Context.Domain.Dialect.Variable(variableName);

            return(attribute.Append(dialectName));
        }
Esempio n. 6
0
        /// <summary>
        /// Appends mappings between the current qualified columns and their properties, e.g. <c>T0."MyColumn" AS "Item.MyValue"</c>, to the projection buffer. Identical to calling <c>Cols().As().Props()</c>.
        /// </summary>
        /// <param name="projection">The current projection</param>
        /// <param name="tblAlias">The table alias to qualify each column name with.</param>
        /// <returns>A new projection containing the appended buffer.</returns>
        public static IProjection Star(this IProjection projection, string tblAlias = null)
        {
            if (!projection.Any())
            {
                throw ProjectionException.AttributesNotFound(projection.Metadata);
            }

            IProjectionMetadata metadata = ProjectionHelper.GetPreferredTableMetadata(projection.Metadata);

            return(projection.With(metadata).Cols(tblAlias).As().Props());
        }
Esempio n. 7
0
        /// <summary>
        /// Appends mappings between the current qualified columns and their properties, e.g. <c>T0."MyColumn" AS "Item.MyValue"</c>, to the projection buffer. Identical to calling <c>Cols().As().Props()</c>.
        /// </summary>
        /// <param name="projection">The current projection</param>
        /// <returns>A new projection containing the appended buffer.</returns>
        public static IProjection Star(this IProjection projection)
        {
            if (!projection.Any())
            {
                throw ProjectionException.FromProjection(projection, "No attributes found.");
            }

            IProjectionMetadata metadata = ProjectionHelper.GetPreferredTableMetadata(projection).Identity.GetMetadata <IProjectionMetadata>();

            return(projection.With(metadata).Cols().As().Props());
        }
Esempio n. 8
0
        /// <summary>
        /// Appends the current value in safe literal form, e.g. <c>1</c>, to the attribute buffer. Parameters are used for unsafe literals.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute Lit(this IProjectionAttribute attribute)
        {
            IField field = ProjectionHelper.GetFieldValue(attribute);

            string literal = attribute.Context.Domain.Dialect.Literal(field?.Value);

            if (literal == null)
            {
                return(attribute.Par());
            }
            else
            {
                return(attribute.Append(literal));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Navigates the current projection to a selected target.
        /// </summary>
        /// <param name="projection">The current projection.</param>
        /// <param name="expression">Expression selecting a projection target.</param>
        /// <returns>A new projection from the selected target.</returns>
        public static IProjection <TProperty> For <TModel, TProperty>(this IProjection <TModel> projection, Expression <Func <TModel, TProperty> > expression)
        {
            IProjectionMetadata metadata = ProjectionHelper.GetMetadataFromRelativeLambda(projection, expression);

            return(projection.With(metadata).Cast <TProperty>());
        }