public IBuildUpdateTable <T> Where(Expression <Func <T, bool> > criteria) { criteria.MustNotBeNull(); _builder.EndEnumeration(); _builder.Where(criteria); return(this); }
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())); }
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())); }
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())); }
/// <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); }