Ejemplo n.º 1
0
        /// <summary>
        /// Delete records by condition.
        /// </summary>
        /// <param name="cond"></param>
        /// <returns></returns>
        public virtual int Delete(Cond <TDbParam> cond)
        {
            var sql = $"DELETE FROM {TableName} WHERE {cond.FetchSql()}";

            LogHelper.WriteLogInfo(sql);
            return(Conn <TDbConn, TDbParam> .ExecuteNonQuery(sql, cond.FetchDbParams()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add condition on WHERE clause.
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public virtual M<TDbConn, TDbParam> Where(Cond<TDbParam> condition)
        {
            var condSql = (condition == null ? string.Empty : condition.FetchSql());
            if (string.IsNullOrEmpty(condSql)) return this;

            WhereConditions.Add(condSql);
            if (condition != null) DbParams.AddRange(condition.FetchDbParams());

            CachedSelectSql = string.Empty;
            return this;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add table for JOIN.
        /// </summary>
        /// <param name="table">Table name</param>
        /// <param name="alias">Alias name of table</param>
        /// <param name="condition">Condition on join</param>
        /// <param name="joinType">One of "INNER", "LEFT", "RIGHT" and "FULL"</param>
        /// <returns></returns>
        public virtual M<TDbConn, TDbParam> Join(string table, string alias = "", Cond<TDbParam> condition = null, string joinType = "INNER")
        {
            if (string.IsNullOrEmpty(table)) return this;

            joinType = joinType.ToUpper();
            if (joinType != "INNER" && joinType != "LEFT" && joinType != "RIGHT" && joinType != "FULL") return this;

            var condSql = (condition == null ? "" : condition.FetchSql());
            if (condition != null) DbParams.AddRange(condition.FetchDbParams());

            JoinTables.Add(
                joinType + " JOIN " +
                (alias == "" ? table : table + " AS " + alias) +
                (condSql == "" ? "" : " ON " + condSql));

            CachedSelectSql = string.Empty;
            return this;
        }