Exemple #1
0
        private SqlSugarClient GetThreadContext(string key)
        {
            SqlSugarClient result = CallContextThread <SqlSugarClient> .GetData(key);

            if (result == null)
            {
                CallContextThread <SqlSugarClient> .SetData(key, new SqlSugarClient(_configs));

                result = CallContextThread <SqlSugarClient> .GetData(key);

                if (this._configAction != null)
                {
                    this._configAction(result);
                }
            }
            return(result);
        }
        private SqlSugarClient GetThreadContext(string key)
        {
            SqlSugarClient result = CallContextThread <SqlSugarClient> .GetData(key);

            if (result == null)
            {
                List <ConnectionConfig> configList = GetCopyConfigs();
                CallContextThread <SqlSugarClient> .SetData(key, new SqlSugarClient(configList));

                result = CallContextThread <SqlSugarClient> .GetData(key);

                if (this._configAction != null)
                {
                    this._configAction(result);
                }
            }
            return(result);
        }
        private Dictionary <string, object> DataReaderToList <T>(IDataReader reader, Type tType, List <PropertyInfo> classProperties, List <T> reval)
        {
            var readerValues = DataReaderToDictionary(reader, tType);
            var mappingKeys  = CallContextThread <Dictionary <string, string> > .GetData("Exp_Select_Mapping_Key");

            if (mappingKeys == null)
            {
                mappingKeys = CallContextAsync <Dictionary <string, string> > .GetData("Exp_Select_Mapping_Key");
            }
            var result = new Dictionary <string, object>();

            foreach (var item in classProperties)
            {
                var name     = item.Name;
                var typeName = tType.Name;
                if (item.PropertyType.IsClass())
                {
                    if (item.PropertyType.FullName == "Newtonsoft.Json.Linq.JObject")
                    {
                        result.Add(name, DeserializeObject <dynamic>(readerValues[item.Name].ToString()));
                    }
                    else if (IsJsonItem(readerValues, name))
                    {
                        result.Add(name, DeserializeObject <Dictionary <string, object> >(readerValues.First().Value.ObjToString()));
                    }
                    else if (IsJsonList(readerValues, item))
                    {
                        result.Add(name, DeserializeObject <List <Dictionary <string, object> > >(readerValues[item.Name.ToLower()].ToString()));
                    }
                    else if (IsBytes(readerValues, item))
                    {
                        result.Add(name, (byte[])readerValues[item.Name.ToLower()]);
                    }
                    else if (item.PropertyType == typeof(object))
                    {
                        result.Add(name, readerValues[item.Name.ToLower()]);
                    }
                    else
                    {
                        result.Add(name, DataReaderToDynamicList_Part(readerValues, item, reval, mappingKeys));
                    }
                }
                else
                {
                    if (readerValues.Any(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        var addValue = readerValues.ContainsKey(name) ? readerValues[name] : readerValues.First(it => it.Key.Equals(name, StringComparison.CurrentCultureIgnoreCase)).Value;
                        if (addValue == DBNull.Value || addValue == null)
                        {
                            if (item.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.DecType, UtilConstants.DobType, UtilConstants.ByteType))
                            {
                                addValue = 0;
                            }
                            else if (item.PropertyType == UtilConstants.GuidType)
                            {
                                addValue = Guid.Empty;
                            }
                            else if (item.PropertyType == UtilConstants.DateType)
                            {
                                addValue = DateTime.MinValue;
                            }
                            else if (item.PropertyType == UtilConstants.StringType)
                            {
                                addValue = null;
                            }
                            else
                            {
                                addValue = null;
                            }
                        }
                        else if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.IntType)
                        {
                            addValue = Convert.ToInt32(addValue);
                        }
                        else if (UtilMethods.GetUnderType(item.PropertyType) == UtilConstants.LongType)
                        {
                            addValue = Convert.ToInt64(addValue);
                        }
                        result.Add(name, addValue);
                    }
                }
            }

            return(result);
        }