Exemple #1
0
 private void SetConditList(List <StorageableInfo <T> > itemList, List <EntityColumnInfo> whereColumns, List <IConditionalModel> conditList)
 {
     ;
     foreach (var dataItem in itemList)
     {
         var condition = new ConditionalCollections()
         {
             ConditionalList = new List <KeyValuePair <WhereType, SqlSugar.ConditionalModel> >()
         };
         conditList.Add(condition);
         int i = 0;
         foreach (var item in whereColumns)
         {
             var value = item.PropertyInfo.GetValue(dataItem.Item, null);
             condition.ConditionalList.Add(new KeyValuePair <WhereType, ConditionalModel>(i == 0?WhereType.Or :WhereType.And, new ConditionalModel()
             {
                 FieldName             = item.DbColumnName,
                 ConditionalType       = ConditionalType.Equal,
                 FieldValue            = value + "",
                 FieldValueConvertFunc = this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL?
                                         UtilMethods.GetTypeConvert(value):null
             }));
             ++i;
         }
     }
 }
 private void SetConditList(List <DataRow> itemList, string[] whereColumns, List <IConditionalModel> conditList)
 {
     ;
     foreach (var dataItem in itemList)
     {
         var condition = new ConditionalCollections()
         {
             ConditionalList = new List <KeyValuePair <WhereType, SqlSugar.ConditionalModel> >()
         };
         conditList.Add(condition);
         int i = 0;
         foreach (var name in whereColumns)
         {
             var value = dataItem[name];
             if (value != null && value.GetType().IsEnum())
             {
                 value = Convert.ToInt64(value);
             }
             condition.ConditionalList.Add(new KeyValuePair <WhereType, ConditionalModel>(i == 0 ? WhereType.Or : WhereType.And, new ConditionalModel()
             {
                 FieldName             = name,
                 ConditionalType       = ConditionalType.Equal,
                 FieldValue            = value + "",
                 FieldValueConvertFunc = this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL ?
                                         UtilMethods.GetTypeConvert(value) : null
             }));
             ++i;
         }
     }
 }
Exemple #3
0
        private ConditionalCollections ToConditionalCollections(ConditionalTree item, ref int indexTree, List <SugarParameter> parameters)
        {
            List <KeyValuePair <WhereType, ConditionalModel> > list = new List <KeyValuePair <WhereType, ConditionalModel> >();
            var index = 0;

            foreach (var it in item.ConditionalList)
            {
                ConditionalModel model = new ConditionalModel();
                if (it.Value is ConditionalModel)
                {
                    model = (ConditionalModel)it.Value;
                }
                else
                {
                    var tree   = it.Value as ConditionalTree;
                    var con    = ToConditionalCollections(tree, ref indexTree, parameters);
                    var sqlobj = ConditionalModelToSql(new List <IConditionalModel> {
                        con
                    }, index);
                    var sql = sqlobj.Key;
                    if (sql.StartsWith(" NULL "))
                    {
                        sql = Regex.Replace(sql, "^ NULL ", it.Key.ToString().ToUpper());
                    }
                    RepairReplicationParameters(ref sql, sqlobj.Value, indexTree);
                    model = new ConditionalModel()
                    {
                        FieldName  = $"[value=sql{UtilConstants.ReplaceKey}]",
                        FieldValue = sql
                    };
                    parameters.AddRange(sqlobj.Value);
                    indexTree++;
                }
                list.Add(new KeyValuePair <WhereType, ConditionalModel>(it.Key, model));
                index++;
            }
            var result = new ConditionalCollections()
            {
                ConditionalList = list
            };

            return(result);
        }
Exemple #4
0
 private void SetConditList(List <StorageableInfo <T> > itemList, List <EntityColumnInfo> whereColumns, List <IConditionalModel> conditList)
 {
     ;
     foreach (var dataItem in itemList)
     {
         var condition = new ConditionalCollections()
         {
             ConditionalList = new List <KeyValuePair <WhereType, SqlSugar.ConditionalModel> >()
         };
         conditList.Add(condition);
         int i = 0;
         foreach (var item in whereColumns)
         {
             var value = item.PropertyInfo.GetValue(dataItem.Item, null);
             if (value != null && value.GetType().IsEnum())
             {
                 if (this.Context.CurrentConnectionConfig.MoreSettings?.TableEnumIsString == true)
                 {
                     value = value.ToString();
                 }
                 else
                 {
                     value = Convert.ToInt64(value);
                 }
             }
             condition.ConditionalList.Add(new KeyValuePair <WhereType, ConditionalModel>(i == 0?WhereType.Or :WhereType.And, new ConditionalModel()
             {
                 FieldName             = item.DbColumnName,
                 ConditionalType       = ConditionalType.Equal,
                 CSharpTypeName        = UtilMethods.GetTypeName(value),
                 FieldValue            = value + "",
                 FieldValueConvertFunc = this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL?
                                         UtilMethods.GetTypeConvert(value):null
             }));
             ++i;
         }
     }
 }
Exemple #5
0
 private static void SetConditList(List <StorageableInfo <T> > itemList, List <EntityColumnInfo> whereColumns, List <IConditionalModel> conditList)
 {
     ;
     foreach (var dataItem in itemList)
     {
         var condition = new ConditionalCollections()
         {
             ConditionalList = new List <KeyValuePair <WhereType, SqlSugar.ConditionalModel> >()
         };
         conditList.Add(condition);
         int i = 0;
         foreach (var item in whereColumns)
         {
             condition.ConditionalList.Add(new KeyValuePair <WhereType, ConditionalModel>(i == 0?WhereType.Or :WhereType.And, new ConditionalModel()
             {
                 FieldName       = item.DbColumnName,
                 ConditionalType = ConditionalType.Equal,
                 FieldValue      = item.PropertyInfo.GetValue(dataItem.Item, null) + ""
             }));
             ++i;
         }
     }
 }