Example #1
0
        public override IBatch End()
        {
            IBatch batch = new MysqlBatch();
            Tuple <List <String>, List <String> > tuple = ConvertHeader(Reduce.GetHeader());
            Type                         t            = typeof(T);
            StringBuilder                sb           = new StringBuilder();
            TableRelevanceMapper         table        = Reduce.GetTable();
            List <ColumnRelevanceMapper> wherecolumns = Reduce.GetWhere();

            sb.Append(table.TableOperatorEnum.GetOperator());
            sb.Append($" {EntityTableMapper.GetTableName(t)} ");
            switch (table.TableOperatorEnum)
            {
            case TableOperatorEnum.Insert:
                sb.Append(GetInsertSql(tuple));
                break;

            case TableOperatorEnum.Update:
                sb.Append(" set ");
                sb.Append(GetUpdateSql(tuple));
                if (wherecolumns.Count == 0)
                {
                    SetNoneWhere(t);
                }
                break;

            case TableOperatorEnum.Delete:
                if (wherecolumns.Count == 0)
                {
                    SetNoneWhere(t);
                }
                break;

            default:
                throw new Exception("请先选择操作种类");
            }
            String where = ConvertToWhere(wherecolumns);
            if (!String.IsNullOrEmpty(where))
            {
                sb.Append($" where {where}");
            }
            batch.SqlBuilder        = sb.ToString();
            batch.DynamicParameters = Reduce.Parameters;
            return(batch);
        }