/// <summary> /// Adds an OR condition to the update statement. /// </summary> /// <typeparam name="T">The type corresponding to the table that records should be updated in.</typeparam> /// <param name="update">The update.</param> /// <param name="condition">The condition.</param> /// <returns>The update statement.</returns> public static UpdateStatement <T> Or <T>(this UpdateStatement <T> update, Expression <Func <T, bool> > condition) { var combined = update.Conditions.Body.OrElse(condition.Body); combined = AnonymousParameterReplacer.Replace(combined, condition.Parameters); update.Conditions = Expression.Lambda <Func <T, bool> >(combined, condition.Parameters); return(update); }
/// <summary> /// Adds an AND condition to the delete statement. /// </summary> /// <typeparam name="T">The type corresponding to the table that records should be deleted from.</typeparam> /// <param name="delete">The delete statement.</param> /// <param name="condition">The condition.</param> /// <returns>The delete statement.</returns> public static DeleteStatement <T> And <T>(this DeleteStatement <T> delete, Expression <Func <T, bool> > condition) { var combined = delete.Conditions.Body.AndAlso(condition.Body); combined = AnonymousParameterReplacer.Replace(combined, condition.Parameters); delete.Conditions = Expression.Lambda <Func <T, bool> >(combined, condition.Parameters); return(delete); }
/// <summary> /// Adds an OR condition to the select statement. /// </summary> /// <typeparam name="T">The type corresponding to the table that records should be selected from.</typeparam> /// <param name="select">The select statement.</param> /// <param name="condition">The condition.</param> /// <returns>The select statement.</returns> public static SelectStatement<T> Or<T>(this SelectStatement<T> select, Expression<Func<T, bool>> condition) { if (select.Conditions != null) { var combined = select.Conditions.Body.OrElse(condition.Body); combined = AnonymousParameterReplacer.Replace(combined, condition.Parameters); select.Conditions = Expression.Lambda<Func<T, bool>>(combined, condition.Parameters); } else { select.Conditions = condition; } return select; }