Пример #1
0
 public void AddWhere(ColumnRelevanceMapper column)
 {
     if (column != null)
     {
         Where.Add(column);
     }
 }
Пример #2
0
 public void AddHeader(ColumnRelevanceMapper column)
 {
     if (column != null)
     {
         Header.Add(column);
     }
 }
Пример #3
0
 public QuerySQLHelper AddWhere(ColumnRelevanceMapper column)
 {
     if (column != null)
     {
         Where.Add(column);
     }
     return(this);
 }
Пример #4
0
 public QuerySQLHelper AddQuery(ColumnRelevanceMapper column)
 {
     lock (_lock)
     {
         Query.Add(column);
     }
     return(this);
 }
Пример #5
0
 public QuerySQLHelper()
 {
     Query   = new List <ColumnRelevanceMapper>();
     Top     = new ColumnRelevanceMapper();
     Table   = new List <TableRelevanceMapper>();
     Where   = new List <ColumnRelevanceMapper>();
     Orderby = new List <String>();
 }
Пример #6
0
        private String ConditionConvert(ColumnRelevanceMapper column, bool isNull = false)
        {
            StringBuilder sb = new StringBuilder();

            //如果 null == item.id 的写法, 会解析成
            //column.ColumnName == null && column.SqlOperatorEnum == SqlOperatorEnum.None
            // null,那么就直接返回"", 接下来的  == item.id 会传递false,然后解析 item.id is null
            if (column.ColumnName == null && column.SqlOperatorEnum == SqlOperatorEnum.None)
            {
                return("");
            }
            //如果是 item.id == null 中写法 那么 == null 则返回 is null
            if (isNull || column.ColumnName == null)
            {
                column.SqlOperatorEnum = SqlEnumConvert(column.SqlOperatorEnum);
            }
            if (column.SqlOperatorEnum == SqlOperatorEnum.EqualNotNull ||
                column.SqlOperatorEnum == SqlOperatorEnum.EqualNull)
            {
                String str = "";
                if (!String.IsNullOrEmpty(column.ColumnName))
                {
                    Type   t          = column.TableName;
                    String tableName  = EntityTableMapper.GetTableName(t);
                    String columnName = EntityTableMapper.GetColoumName(t, column.ColumnName);
                    str = $"{tableName}.{columnName}";
                }
                return($"{str} {column.SqlOperatorEnum.GetOperator()}");
            }
            if (column.SqlOperatorEnum != SqlOperatorEnum.None)
            {
                sb.Append(column.SqlOperatorEnum.GetOperator());
            }
            //如果是 直接传递字符串 如 id in (select id from xxx)中,则 括号中则直接拼接,而不用@数字
            //如果是 item.id == 1 中的  == 1,那么只 保存 = @ColumnName
            if (column.TableName == null)
            {
                if (column.ColumnName.IndexOf("(") != -1)
                {
                    sb.Append($" {column.ColumnName} ");
                }
                else
                {
                    sb.Append($"@{column.ColumnName}");
                }
            }
            //如果是 item.id == 1 中的  item.id ,那么就保存 tablename.id
            else
            {
                Type   t          = column.TableName;
                String tableName  = EntityTableMapper.GetTableName(t);
                String columnName = EntityTableMapper.GetColoumName(t, column.ColumnName);
                sb.Append($" {tableName}.{columnName} ");
            }
            return(sb.ToString());
        }
Пример #7
0
        public async Task <IEnumerable <Tuple <T, K, P> > > ExecuteReaderAsync <K, P>(IBatch batch, List <ColumnRelevanceMapper> mapper) where K : IEntity, new() where P : IEntity, new()
        {
            if (SqlExecuteExtensionAction.Instance.BatchAction != null)
            {
                SqlExecuteExtensionAction.Instance.AddContext(batch);
            }
            List <Tuple <T, K, P> > entitybuffer = new List <Tuple <T, K, P> >(128);

            using (var Connection = Create.Invoke())
            {
                var reader = await Connection.ExecuteReaderAsync(batch.SqlBuilder, batch.DynamicParameters, commandTimeout : 3600);

                while (reader.Read())
                {
                    T    t  = new T();
                    Type t1 = typeof(T);
                    K    k  = new K();
                    Type k1 = typeof(K);
                    P    p  = new P();
                    Type p1 = typeof(P);
                    for (Int32 i = 0; i < reader.FieldCount; i++)
                    {
                        Object obj = reader.GetValue(i);
                        if (obj != null)
                        {
                            ColumnRelevanceMapper column = mapper[i];
                            if (column.TableName == t1)
                            {
                                PropertyValueExpression <T> .SetValue(t, column.ColumnName, obj);
                            }
                            else if (column.TableName == k1)
                            {
                                PropertyValueExpression <K> .SetValue(k, column.ColumnName, obj);
                            }
                            else
                            {
                                PropertyValueExpression <P> .SetValue(p, column.ColumnName, obj);
                            }
                        }
                    }
                    Tuple <T, K, P> tuple = new Tuple <T, K, P>(t, k, p);
                    entitybuffer.Add(tuple);
                }
            }
            return(entitybuffer);
        }
Пример #8
0
        private String ConditionConvert(ColumnRelevanceMapper column, bool isNull = false)
        {
            StringBuilder sb = new StringBuilder();

            //如果 null == item.id 中写法 null,那么返回"", == item.id 返回item.id is null
            //如果是 item.id == null 中写法 那么 == null 则返回 is null
            if (column.ColumnName == null && column.SqlOperatorEnum == SqlOperatorEnum.None)
            {
                return("");
            }
            if (isNull || column.ColumnName == null)
            {
                column.SqlOperatorEnum = SqlEnumConvert(column.SqlOperatorEnum);
            }
            if (column.SqlOperatorEnum == SqlOperatorEnum.EqualNotNull ||
                column.SqlOperatorEnum == SqlOperatorEnum.EqualNull)
            {
                String str = "";
                if (!String.IsNullOrEmpty(column.ColumnName))
                {
                    Type   t          = column.TableName;
                    String tableName  = EntityTableMapper.GetTableName(t);
                    String columnName = EntityTableMapper.GetColoumName(t, column.ColumnName);
                    str = $"{tableName}.{columnName}";
                }
                return($"{str} {column.SqlOperatorEnum.GetOperator()}");
            }
            if (column.SqlOperatorEnum != SqlOperatorEnum.None)
            {
                sb.Append(column.SqlOperatorEnum.GetOperator());
            }
            //如果是 item.id = 1 中的  = 1,那么只 保存 = @ColumnName
            if (column.TableName == null)
            {
                sb.Append($"@{column.ColumnName}");
            }
            else
            {
                Type   t          = column.TableName;
                String tableName  = EntityTableMapper.GetTableName(t);
                String columnName = EntityTableMapper.GetColoumName(t, column.ColumnName);
                sb.Append($" {tableName}.{columnName} ");
            }
            return(sb.ToString());
        }
Пример #9
0
        private void SetNoneWhere(Type t)
        {
            String pk = EntityTableMapper.GetPkColumn(t);

            if (String.IsNullOrEmpty(pk))
            {
                throw new ArgumentException("请使用带主键的或者添加删选条件");
            }
            String pkValue = ValuePairs[pk].ColumnName;
            ColumnRelevanceMapper column = new ColumnRelevanceMapper();

            column.ColumnName = pk;
            column.TableName  = t;
            ColumnRelevanceMapper value = new ColumnRelevanceMapper();

            value.ColumnName      = pk;
            value.SqlOperatorEnum = SqlOperatorEnum.Equal;
            Reduce.AddWhere(column);
            Reduce.AddWhere(value);
        }
Пример #10
0
 public BatchParameterReduce AddWhere(ColumnRelevanceMapper column)
 {
     RenewalHelper.AddWhere(column);
     return(this);
 }