Ejemplo n.º 1
0
        /// <summary>
        /// Adds a table to the FROM statement with "T0" alias and sets it as target for future field selections.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="entity">The entity.</param>
        /// <returns>
        /// The query itself.
        /// </returns>
        /// <exception cref="ArgumentNullException">row</exception>
        public static SqlQuery From(this SqlQuery query, IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("row");
            }

            if (entity as IRow != null)
            {
                var fields = (entity as IRow).Fields;
                query.From(fields);
                if (!query.IsDialectOverridden)
                {
                    query.Dialect(fields.Dialect);
                }
            }
            else
            {
                if (entity as IAlias != null && ((entity as IAlias).Name == "t0" || (entity as IAlias).Name == "T0") && (entity as IAlias).Table == entity.Table)
                {
                    query.From(entity as IAlias);
                }
                else
                {
                    query.From(entity.Table, Alias.T0);
                }
            }

            return(query.Into(entity));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a table to the FROM statement with "T0" alias and sets it as target for future field selections.
        /// </summary>
        /// <param name="row">Row object.</param>
        /// <returns>The query itself.</returns>
        public static SqlQuery From(this SqlQuery query, IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("row");
            }

            var row = entity as Row;

            if (row != null)
            {
                query.From(row.GetFields());
            }
            else
            {
                var alias = entity as IAlias;
                if (alias != null && (alias.Name == "t0" || alias.Name == "T0") && alias.Table == entity.Table)
                {
                    query.From(alias);
                }
                else
                {
                    query.From(entity.Table, Alias.T0);
                }
            }

            return(query.Into(entity));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a table to the FROM statement with "T0" alias and sets it as target for future field selections.
        /// </summary>
        /// <param name="row">Row object.</param>
        /// <returns>The query itself.</returns>
        public static SqlQuery From(this SqlQuery query, IEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("row");
            }

            var row = entity as Row;

            if (row != null)
            {
                var fields = row.GetFields();
                query.From(fields);
                if (!query.IsDialectOverridden && !string.IsNullOrEmpty(fields.connectionKey))
                {
                    var cs = SqlConnections.TryGetConnectionString(fields.connectionKey);
                    if (cs != null)
                    {
                        query.Dialect(cs.Dialect);
                    }
                }
            }
            else
            {
                var alias = entity as IAlias;
                if (alias != null && (alias.Name == "t0" || alias.Name == "T0") && alias.Table == entity.Table)
                {
                    query.From(alias);
                }
                else
                {
                    query.From(entity.Table, string.Empty, Alias.T0);
                }
            }

            return(query.Into(entity));
        }
Ejemplo n.º 4
0
 public void IntoRowIndexCanBeSetToMinusOneWithNull()
 {
     var entity = new MyEntity() { Table = "x" };
     var query = new SqlQuery().From(entity).Select("x1");
     Assert.Equal(((ISqlQueryExtensible)query).Columns.ElementAt(0).IntoRowIndex, 0);
     query.Into(null).Select("x2");
     Assert.Equal(((ISqlQueryExtensible)query).Columns.ElementAt(1).IntoRowIndex, -1);
     Assert.Equal(1, ((ISqlQueryExtensible)query).IntoRows.Count);
     Assert.Equal(entity, ((ISqlQueryExtensible)query).IntoRows[0]);
 }
Ejemplo n.º 5
0
 public void IntoRowCanBeChanged()
 {
     var entity1 = new MyEntity() { Table = "x" };
     var query = new SqlQuery().From(entity1).Select("x1");
     Assert.Equal(((ISqlQueryExtensible)query).Columns.ElementAt(0).IntoRowIndex, 0);
     var entity2 = new MyEntity() { Table = "y" };
     query.Into(entity2).Select("y1");
     Assert.Equal(1, ((ISqlQueryExtensible)query).Columns.ElementAt(1).IntoRowIndex);
     Assert.Equal(2, ((ISqlQueryExtensible)query).IntoRows.Count);
     Assert.Equal(entity1, ((ISqlQueryExtensible)query).IntoRows[0]);
     Assert.Equal(entity2, ((ISqlQueryExtensible)query).IntoRows[1]);
 }