mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	- 优化 字典crud TableInfo 合并规则;#1180
This commit is contained in:
		@@ -94,10 +94,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
        public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary<string, bool> changedDict)
 | 
					        public static void AuditDataValue(object sender, T1 data, IFreeSql orm, TableInfo table, Dictionary<string, bool> changedDict)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (data == null || table == null) return;
 | 
					            if (data == null || table == null) return;
 | 
				
			||||||
            if (typeof(T1) == typeof(object) && new[]
 | 
					            if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    table.Type, table.TypeLazy
 | 
					 | 
				
			||||||
                }.Contains(data.GetType()) == false)
 | 
					 | 
				
			||||||
                throw new Exception(CoreStrings.DataType_AsType_Inconsistent(data.GetType().DisplayCsharp(), table.Type.DisplayCsharp()));
 | 
					                throw new Exception(CoreStrings.DataType_AsType_Inconsistent(data.GetType().DisplayCsharp(), table.Type.DisplayCsharp()));
 | 
				
			||||||
            if (orm.Aop.AuditValueHandler == null) return;
 | 
					            if (orm.Aop.AuditValueHandler == null) return;
 | 
				
			||||||
            foreach (var col in table.Columns.Values)
 | 
					            foreach (var col in table.Columns.Values)
 | 
				
			||||||
@@ -116,32 +113,11 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public IInsertOrUpdate<T1> SetSource(T1 source) => this.SetSource(new[]
 | 
					        public IInsertOrUpdate<T1> SetSource(T1 source) => this.SetSource(new[] { source });
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            source
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        public IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null)
 | 
					        public IInsertOrUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (source == null || source.Any() == false) return this;
 | 
					            if (source == null || source.Any() == false) return this;
 | 
				
			||||||
            if (source is IEnumerable<IDictionary<string, object>> dicType)
 | 
					            UpdateProvider<T1>.GetDictionaryTableInfo(source, _orm, ref _table);
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                var tempDict = new Dictionary<string, object>();
 | 
					 | 
				
			||||||
                foreach (var item in dicType)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    foreach (string key in item.Keys)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        if (!tempDict.ContainsKey(key) && !(item[key] is null))
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            tempDict[key] = item[key];
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                UpdateProvider<IDictionary>.GetDictionaryTableInfo(tempDict, _orm, ref _table);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                UpdateProvider<T1>.GetDictionaryTableInfo(source.FirstOrDefault(), _orm, ref _table);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
					            AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
				
			||||||
            _source.AddRange(source.Where(a => a != null));
 | 
					            _source.AddRange(source.Where(a => a != null));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -257,16 +233,8 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
        public NativeTuple<List<T1>[], List<T1>[]> SplitSourceByIdentityValueIsNull(List<T1> source)
 | 
					        public NativeTuple<List<T1>[], List<T1>[]> SplitSourceByIdentityValueIsNull(List<T1> source)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (source.Any() == false) return NativeTuple.Create(new List<T1>[0], new List<T1>[0]);
 | 
					            if (source.Any() == false) return NativeTuple.Create(new List<T1>[0], new List<T1>[0]);
 | 
				
			||||||
            if (_SplitSourceByIdentityValueIsNullFlag == 1)
 | 
					            if (_SplitSourceByIdentityValueIsNullFlag == 1) return NativeTuple.Create(new[] { source }, new List<T1>[0]);
 | 
				
			||||||
                return NativeTuple.Create(new[]
 | 
					            if (_SplitSourceByIdentityValueIsNullFlag == 2) return NativeTuple.Create(new List<T1>[0], new[] { source });
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    source
 | 
					 | 
				
			||||||
                }, new List<T1>[0]);
 | 
					 | 
				
			||||||
            if (_SplitSourceByIdentityValueIsNullFlag == 2)
 | 
					 | 
				
			||||||
                return NativeTuple.Create(new List<T1>[0], new[]
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    source
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
            if (IdentityColumn == null || _tempPrimarys != _table.Primarys) return NativeTuple.Create(LocalSplitSourceByAsTable(source), new List<T1>[0]);
 | 
					            if (IdentityColumn == null || _tempPrimarys != _table.Primarys) return NativeTuple.Create(LocalSplitSourceByAsTable(source), new List<T1>[0]);
 | 
				
			||||||
            var item1 = new List<T1>();
 | 
					            var item1 = new List<T1>();
 | 
				
			||||||
            var item2 = new List<T1>();
 | 
					            var item2 = new List<T1>();
 | 
				
			||||||
@@ -291,10 +259,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                    }).GroupBy(a => a.splitKey, a => a.item).Select(a => a.ToList()).ToArray();
 | 
					                    }).GroupBy(a => a.splitKey, a => a.item).Select(a => a.ToList()).ToArray();
 | 
				
			||||||
                    return atarr;
 | 
					                    return atarr;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                return new[]
 | 
					                return new[] { loc1 };
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    loc1
 | 
					 | 
				
			||||||
                };
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,7 +133,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            if (source != null)
 | 
					            if (source != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                UpdateProvider<T1>.GetDictionaryTableInfo(source.FirstOrDefault(), _orm, ref _table);
 | 
					                UpdateProvider<T1>.GetDictionaryTableInfo(source, _orm, ref _table);
 | 
				
			||||||
                AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
					                AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
				
			||||||
                _source.AddRange(source);
 | 
					                _source.AddRange(source);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -144,7 +144,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
            if (source != null)
 | 
					            if (source != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                source = source.Where(a => a != null).ToList();
 | 
					                source = source.Where(a => a != null).ToList();
 | 
				
			||||||
                UpdateProvider<T1>.GetDictionaryTableInfo(source.FirstOrDefault(), _orm, ref _table);
 | 
					                UpdateProvider<T1>.GetDictionaryTableInfo(source, _orm, ref _table);
 | 
				
			||||||
                AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
					                AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
				
			||||||
                _source.AddRange(source);
 | 
					                _source.AddRange(source);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -451,6 +451,20 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static void GetDictionaryTableInfo(IEnumerable<T1> source, IFreeSql orm, ref TableInfo table)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (table == null && typeof(T1) == typeof(Dictionary<string, object>) && source is IEnumerable<Dictionary<string, object>> dicType)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var tempDict = new Dictionary<string, object>();
 | 
				
			||||||
 | 
					                foreach (var item in dicType)
 | 
				
			||||||
 | 
					                    foreach (string key in item.Keys)
 | 
				
			||||||
 | 
					                        if (!tempDict.ContainsKey(key) && !(item[key] is null))
 | 
				
			||||||
 | 
					                            tempDict[key] = item[key];
 | 
				
			||||||
 | 
					                UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(tempDict, orm, ref table);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            GetDictionaryTableInfo(source.FirstOrDefault(), orm, ref table);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        public static void GetDictionaryTableInfo(T1 source, IFreeSql orm, ref TableInfo table)
 | 
					        public static void GetDictionaryTableInfo(T1 source, IFreeSql orm, ref TableInfo table)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (table == null && typeof(T1) == typeof(Dictionary<string, object>))
 | 
					            if (table == null && typeof(T1) == typeof(Dictionary<string, object>))
 | 
				
			||||||
@@ -493,7 +507,7 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
        public IUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null, bool ignoreVersion = false)
 | 
					        public IUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null, bool ignoreVersion = false)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (source == null || source.Any() == false) return this;
 | 
					            if (source == null || source.Any() == false) return this;
 | 
				
			||||||
            GetDictionaryTableInfo(source.FirstOrDefault(), _orm, ref _table);
 | 
					            GetDictionaryTableInfo(source, _orm, ref _table);
 | 
				
			||||||
            AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
					            AuditDataValue(this, source, _orm, _table, _auditValueChangedDict);
 | 
				
			||||||
            _source.AddRange(source.Where(a => a != null));
 | 
					            _source.AddRange(source.Where(a => a != null));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user