예제 #1
0
 public IBuildUpdateTable <T> Where(Expression <Func <T, bool> > criteria)
 {
     criteria.MustNotBeNull();
     _builder.EndEnumeration();
     _builder.Where(criteria);
     return(this);
 }
예제 #2
0
        public static int DeleteFrom <T>(this IAccessDb db, Expression <Func <T, bool> > criteria = null)
        {
            var builder = new ExpressionSqlBuilder <T>(db.Provider.BuilderHelper);

            builder.WriteDelete();
            if (criteria != null)
            {
                builder.Where(criteria);
            }
            return(db.ExecuteCommand(builder.ToString(), builder.Parameters.ToArray()));
        }
예제 #3
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()));
        }
예제 #4
0
        public static int DeleteFrom <T>(this DbConnection db, Expression <Func <T, bool> > criteria = null, string schemaName = null)
        {
            var builder = new ExpressionSqlBuilder <T>(db.GetProvider().BuilderHelper, schemaName);

            builder.WriteDelete();
            if (criteria != null)
            {
                builder.Where(criteria);
            }
            return(db.Execute(builder.ToString(), builder.Parameters.ToArray()));
        }
예제 #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);
        }