/// <summary> /// This method will requery an entity from the database, refreshing /// the values of all attributes to match that in the database. /// </summary> /// <param name="entity">The entity object to reload attributes to</param> /// <returns> /// true if the entity was successfully retrieved from the databse /// and its attributes reloaded; false otherwise /// </returns> public bool Reload(ref TEntity entity) { // Begin a new Select Query SelectQueryBuilder query = new SelectQueryBuilder(Context); query.From(EntityTable.TableName).SelectAll().Take(1); // Grab the primary keys foreach (string attrName in EntityTable.PrimaryKeys) { // Add column expression AttributeInfo attribute = EntityTable.GetAttribute(attrName); query.Where(attrName, Comparison.Equals, attribute.Property.GetValue(entity)); } // Create command using (SQLiteCommand command = query.BuildCommand()) using (SQLiteDataReader reader = command.ExecuteReader()) { // Do we have a result? if (reader.HasRows) { // Read the row reader.Read(); entity = Context.ConvertToEntity <TEntity>(EntityTable, reader); // Close reader and return positive reader.Close(); return(true); } else { reader.Close(); return(false); } } }