/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="output"></param> /// <returns></returns> public virtual string GenerateUpdate(IEntityExplain entity, ParameterCollection output) { if (entity.AnySetted() == false) { return(null); } var fields = entity.GetSettedFields(); var conditions = entity.GetFieldValues(entity.GetKeys()); if (conditions == null || conditions.Any() == false) { throw new ArgumentException("实体对象缺少主键值。"); } var values = entity.GetFieldValues(fields.Where(x => entity.IsKey(x) == false)); return(_stmBuilder.Update(entity, values, conditions, output, SqlOptions.None)); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="output"></param> /// <param name="includeIncrement"></param> /// <param name="incrementFieldName"> </param> /// <returns></returns> public virtual string GenerateInsert(IEntityExplain entity, ParameterCollection output, bool includeIncrement, out bool hasIncrement, string incrementFieldName = null) { if (entity.AnySetted() == false) { hasIncrement = false; return(null); } var fields = entity.GetSettedFields(); var values = entity.GetFieldValues(fields); if (includeIncrement && entity.Increment != null) { var sql = new StringBuilder(); sql.AppendLine(_stmBuilder.Insert(entity, values, output, SqlOptions.None)); sql.AppendLine(_stmBuilder.IncrementByQuery(entity, incrementFieldName, SqlOptions.None)); hasIncrement = true; return(sql.ToString()); } // hasIncrement = false; return(_stmBuilder.Insert(entity, values, output, SqlOptions.None)); }