public async Task <T> Retrieve <T>(T item) where T : class { string whereStr = $"WHERE {ObjectEvaluator.ToWhereString<T>(item)}"; var result = await QueryBuilder.Select <T>().Where(whereStr).ExecuteQueryAsync(); return(result.FirstOrDefault()); }
public Task Remove <T>(T item) where T : class { string queryStr = $"DELETE FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"WHERE {ObjectEvaluator.ToWhereString<T>(item)}"; return(QueryBuilder.ExecuteQueryAsync <T>(queryStr)); }
public void RemoveRange <T>(IEnumerable <T> items) where T : class { string queryStr = $"DELETE FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"WHERE {ObjectEvaluator.ToWhereString<T>(items)}"; QueryBuilder.ExecuteQuery <T>(queryStr); }
public async Task <bool> Contains <T>(T item) where T : class { string whereStr = $"WHERE {ObjectEvaluator.ToWhereString<T>(item)}"; string queryStr = $"SELECT * " + $"FROM {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"{whereStr}"; return((await QueryBuilder.ExecuteQueryAsync <T>(queryStr)).Any()); }
public Task <IEnumerable <T> > RetrieveRange <T>(IEnumerable <T> items) where T : class { string whereConditions = items.Select(item => $"({ObjectEvaluator.ToWhereString<T>(item)}) OR") .Aggregate((i1, i2) => $"{i1} {i2}").Trim(); Regex rg = new Regex(" OR$"); string whereStr = $"WHERE {rg.Replace(whereConditions, "")}"; return(QueryBuilder.Select <T>().Where(whereStr).ExecuteQueryAsync()); }
public Task Set <T>(T oldValue, T newValue) where T : class { string setStr = $"SET {ObjectEvaluator.ToWhereString<T>(newValue).Replace(" AND ", ", \n")}"; string whereStr = $"WHERE {ObjectEvaluator.ToWhereString<T>(oldValue)}"; string queryStr = $"UPDATE {StringToolkit.PascalToUnderscore(typeof(T).Name)} " + $"{setStr} {whereStr}"; return(QueryBuilder.ExecuteNonQueryAsync(queryStr)); }
public IFilterableQueryBuilder <TEntity> Set(dynamic newValues) { ParameterMap = ObjectEvaluator.ToDictionary(newValues); Console.WriteLine(string.Join("\n", ParameterMap)); StringBuilder setStringBuilder = new StringBuilder(); setStringBuilder.Append(ObjectEvaluator.EvaluateToParameterizedSqlString(ParameterMap)); string setStr = setStringBuilder.ToString(); var cmd = Connection.CreateCommand(); ParameterCollection = cmd.CreateParameters((object)newValues); QueryStringBuilder.Append($" SET {setStr}"); return(this); }