public bool Update <T>(T entity, string tableName = null, int?commandTimeout = null) where T : class
        {
            IClassMapper <T> classMapper = ClassMapperFactory.GetMapper <T>(tableName);

            classMapper.BeforeSave(entity);
            KeyConditionResult keyConditionResult = SqlGenerator.GetKeyConditionByEntity(classMapper, entity);

            if (classMapper.GetVersionMap() != null)
            {
                int oldVersion = (int)classMapper.GetVersionMap().PropertyInfo.GetValue(entity, null);
                keyConditionResult.Sql = string.Format("{0} AND {1}={2}", keyConditionResult.Sql,
                                                       SqlGenerator.DbProvider.QuoteString(classMapper.GetVersionMap().ColumnName), oldVersion);
                classMapper.GetVersionMap().PropertyInfo.SetValue(entity, oldVersion + 1, null);
            }
            SqlConvertResult sqlConvertResult = SqlGenerator.Update(classMapper, keyConditionResult.Sql, keyConditionResult.Parameters, entity);

            sqlConvertResult.Parameters.AddDynamicParams(entity);
            bool flag = DbConnection.Execute(sqlConvertResult.Sql, sqlConvertResult.Parameters, DbTransaction, commandTimeout, CommandType.Text) > 0;

            if (flag)
            {
                classMapper.AfterSave(entity);
            }
            return(flag);
        }