public static async Task <TModel> FindAsync(string query, params object[] args) { return((await DbFacade.GetDatabaseConnection(ConnectionName).BroccoQuery <TModel>(string.Format("{0} {1}", SelectSqlCache, query), args)).SingleOrDefault()); }
/// <summary> /// /// </summary> /// <returns>The number of rows affected</returns> public int PersistentDelete() { return(DbFacade.GetDatabaseConnection(ConnectionName).Delete(this)); }
public static List <TModel> FindPage(long page, long itemsPerPage, string _sql, bool withTrashed = false, params object[] args) { return(DbFacade.GetDatabaseConnection(ConnectionName).Page <TModel>(page, itemsPerPage, _sql, null).Items); }
/// <summary> /// /// </summary> public void Save() { //* initialize an object for execute var toExecute = FilterTrashed(); //* set the modified records. The logic behind will handle it without hassle ModifiedAt = DateTime.Now; if (Id == 0) { CreatedAt = DateTime.Now; //* Need to form value to save var recordsToInsert = from pocoCol in PocoColumns.Values where PropertyBag.ContainsKey(pocoCol.PropertyInfo.Name) select new { pocoCol.ColumnName, value = PropertyBag[pocoCol.PropertyInfo.Name] }; //* The condition here is when the number of records to add is more than 2, which is excluding ModifiedAt and CreatedAt if (recordsToInsert.Count() > 2) { //* Do insert here toExecute .Insert((from c in recordsToInsert select c.ColumnName).ToArray()) .Into(TableName); foreach (var red in recordsToInsert) { toExecute.Value(red.ColumnName, red.value); } var ret = DbFacade.GetDatabaseConnection(ConnectionName).Insert(TableName, this); //* implement finding the records by all matches if (ret != null && ret.IsNumber()) { Id = long.Parse(ret.ToString()); } else { Id = long.MinValue; } } } else { UpdateResult = int.MinValue; //* Need to form value to save var recordsToUpdate = from ModifiedProp in ModifiedColumns let pocoCol = PocoColumns[ModifiedProp] select new { pocoCol.ColumnName, value = PropertyBag[ModifiedProp] }; //* The condition here is excluding ModifiedAt if (recordsToUpdate.Count() > 1) { //* Do update here toExecute.Update().Where((model) => model.Id == Id); foreach (var red in recordsToUpdate) { toExecute.Set(red.ColumnName, red.value); } UpdateResult = DbFacade.GetDatabaseConnection(ConnectionName).Update(this); } OnModelSaved(this, null); } }
//* TODO: Fix for QueryAll issue to support caching public static IEnumerable <TModel> QueryAll(string query, params object[] args) { return(DbFacade.GetDatabaseConnection(ConnectionName).Query <TModel>(query, args)); }