/// <summary> /// Generates an "UPDATE tablename SET columns = ? WHERE pkColumns = ?" statement for a POCO of Type T. /// </summary> public string GenerateUpdate <T>() { PocoData pocoData = _pocoDataFactory.GetPocoData <T>(); if (pocoData.Columns.Count == 0) { throw new InvalidOperationException(string.Format(NoColumns, "UPDATE", typeof(T).Name)); } if (pocoData.MissingPrimaryKeyColumns.Length > 0) { throw new InvalidOperationException(string.Format(MissingPkColumns, "UPDATE", typeof(T).Name, pocoData.MissingPrimaryKeyColumns.ToCommaDelimitedString())); } string nonPkColumns = pocoData.GetNonPrimaryKeyColumns().Select(c => string.Format("{0} = ?", c.ColumnName)).ToCommaDelimitedString(); string pkColumns = string.Join(" AND ", pocoData.GetPrimaryKeyColumns().Select(c => string.Format("{0} = ?", c.ColumnName))); return(string.Format("UPDATE {0} SET {1} WHERE {2}", pocoData.TableName, nonPkColumns, pkColumns)); }