/// <summary> /// Deletes the specified entity or entities based off provided expression. /// </summary> /// <param name="entity"></param> public void Delete <T>(Expression <Func <T, bool> > expression, bool deleteAll = false) { string query = ""; try { string table = typeof(T).Name; string condition = QueryUtil.Translate(expression); query = deleteAll ? BaseQuery.DELETE_WHERE <T>(new string[] { table, condition }) : BaseQuery.DELETE_FIRST_WHERE <T>(new string[] { table, condition }); SqlUtil.ExecuteDynamicQuery(query); } catch (Exception ex) { var message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += "\n" + ex.Message; } throw new Exception(message); } }
/// <summary> /// Deletes the specified entity or entities based off provided expression. /// </summary> /// <param name="entity"></param> public void Delete <T>(Expression <Func <T, bool> > expression, bool deleteAll = false) { try { string table = typeof(T).Name; string condition = expression == null ? "" : QueryUtil.Translate(expression); string query = deleteAll ? (string.IsNullOrWhiteSpace(condition) ? BaseQuery.DELETE_ALL <T>(table) : BaseQuery.DELETE_WHERE <T>(new string[] { table, condition })) : BaseQuery.DELETE_FIRST_WHERE <T>(new string[] { table, condition }); SqlUtil.ExecuteDynamicQuery(query); } catch (Exception ex) { throw new Exception(CustomErrorResponse(ex)); } }