Exemple #1
0
 public IBuildUpdateTable <T> Set(Expression <Func <T, object> > column, Expression <Func <T, object> > statement)
 {
     _builder.Append(" {0}=".ToFormat(_db.Provider.EscapeName(column.Body.GetPropertyName())));
     _builder.Write(statement);
     _builder.Append(",");
     return(this);
 }
Exemple #2
0
 public UpdateTableBuilder(IAccessDb db)
 {
     db.MustNotBeNull();
     _db      = db;
     _builder = new ExpressionSqlBuilder <T>(db.Provider.BuilderHelper);
     _builder.Append("update ").WriteTableName();
     _builder.Append(" set");
 }
Exemple #3
0
 public UpdateTableBuilder(DbConnection db)
 {
     db.MustNotBeNull();
     _db      = db;
     _builder = new ExpressionSqlBuilder <T>(db.GetProvider().BuilderHelper);
     _builder.Append("update ").WriteTableName();
     _builder.Append(" set");
 }
Exemple #4
0
        public static long Count <T>(this DbConnection db, Expression <Func <T, bool> > criteria = null)
        {
            var builder = new ExpressionSqlBuilder <T>(db.GetProvider().BuilderHelper);

            builder.Append("select count(*) from ").WriteTableName();
            if (criteria != null)
            {
                builder.Where(criteria);
            }
            return(db.GetValue <long>(builder.ToString(), builder.Parameters.ToArray()));
        }
Exemple #5
0
        /// <summary>
        /// Checks if the table has any rows with optional criteria
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static bool HasAnyRows <T>(this DbConnection db, Expression <Func <T, bool> > criteria = null)
        {
            var builder = new ExpressionSqlBuilder <T>(db.GetProvider().BuilderHelper);

            builder
            .Append("select 1 from ")
            .WriteTableName()
            .Append(" where exists(select * from ")
            .WriteTableName();
            if (criteria != null)
            {
                builder.Where(criteria);
            }
            builder.Append(")");
            var r = db.GetValue <int?>(builder.ToString(), builder.Parameters.ToArray());

            if (r.HasValue)
            {
                return(true);
            }
            return(false);
        }