mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 修复 UpdateDict 不支持 SET NULL 的更新;#1257
This commit is contained in:
		@@ -362,10 +362,13 @@ namespace base_entity
 | 
				
			|||||||
            public string code { get; set; }
 | 
					            public string code { get; set; }
 | 
				
			||||||
            public string parentcode { get; set; }
 | 
					            public string parentcode { get; set; }
 | 
				
			||||||
            public string name { get; set; }
 | 
					            public string name { get; set; }
 | 
				
			||||||
 | 
					            [Column(MapType = typeof(string))]
 | 
				
			||||||
 | 
					            public string JoinTest01Enum { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            [JoinCondition("a.parentcode = b.code")]
 | 
					            [JoinCondition("a.parentcode = b.code")]
 | 
				
			||||||
            public JoinTest01 Parent { get; set; }
 | 
					            public JoinTest01 Parent { get; set; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        public enum JoinTest01Enum { f1, f2, f3 }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        static void Main(string[] args)
 | 
					        static void Main(string[] args)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -424,6 +427,45 @@ namespace base_entity
 | 
				
			|||||||
            BaseEntity.Initialization(fsql, () => _asyncUow.Value);
 | 
					            BaseEntity.Initialization(fsql, () => _asyncUow.Value);
 | 
				
			||||||
            #endregion
 | 
					            #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Dictionary<string, object> dic = new Dictionary<string, object>();
 | 
				
			||||||
 | 
					            dic.Add("id", 1);
 | 
				
			||||||
 | 
					            dic.Add("name", "xxxx");
 | 
				
			||||||
 | 
					            var diclist = new List<Dictionary<string, object>>();
 | 
				
			||||||
 | 
					            diclist.Add(dic);
 | 
				
			||||||
 | 
					            diclist.Add(new Dictionary<string, object>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ["id"] = 2,
 | 
				
			||||||
 | 
					                ["name"] = "123,1234,123444"
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var sqss = fsql.InsertDict(dic).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					            var sqss2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					            sqss = fsql.InsertDict(dic).AsTable("table1").NoneParameter(false).ToSql();
 | 
				
			||||||
 | 
					            sqss2 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter(false).ToSql();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            dic["xxx"] = null;
 | 
				
			||||||
 | 
					            var sqlupd1 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").ToSql();
 | 
				
			||||||
 | 
					            var sqlupd2 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").ToSql();
 | 
				
			||||||
 | 
					            var sqlupd11 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
 | 
				
			||||||
 | 
					            var sqlupd22 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var sqldel1 = fsql.DeleteDict(dic).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					            var sqldel2 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					            diclist[1]["title"] = "newtitle";
 | 
				
			||||||
 | 
					            var sqldel3 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					            diclist.Clear();
 | 
				
			||||||
 | 
					            diclist.Add(new Dictionary<string, object>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ["id"] = 1
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            diclist.Add(new Dictionary<string, object>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ["id"] = 2
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            var sqldel4 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            fsql.Aop.ParseExpression += (_, e) =>
 | 
					            fsql.Aop.ParseExpression += (_, e) =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (e.Expression is MemberExpression memExp == false) return;
 | 
					                if (e.Expression is MemberExpression memExp == false) return;
 | 
				
			||||||
@@ -447,6 +489,7 @@ namespace base_entity
 | 
				
			|||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (parmExp == null) return;
 | 
					                if (parmExp == null) return;
 | 
				
			||||||
 | 
					                if (e.Tables == null) return;
 | 
				
			||||||
                var oldTables = e.Tables.ToArray();
 | 
					                var oldTables = e.Tables.ToArray();
 | 
				
			||||||
                var result = e.FreeParse(e.Expression);
 | 
					                var result = e.FreeParse(e.Expression);
 | 
				
			||||||
                for (var a = oldTables.Length; a < e.Tables.Count; a++)
 | 
					                for (var a = oldTables.Length; a < e.Tables.Count; a++)
 | 
				
			||||||
@@ -467,6 +510,8 @@ namespace base_entity
 | 
				
			|||||||
            var joinsql1 = fsql.Select<JoinTest01>()
 | 
					            var joinsql1 = fsql.Select<JoinTest01>()
 | 
				
			||||||
                .Include(a => a.Parent.Parent)
 | 
					                .Include(a => a.Parent.Parent)
 | 
				
			||||||
                .Where(a => a.Parent.Parent.code == "001")
 | 
					                .Where(a => a.Parent.Parent.code == "001")
 | 
				
			||||||
 | 
					                .Where(a => a.JoinTest01Enum == JoinTest01Enum.f3.ToString())
 | 
				
			||||||
 | 
					                .Where(a => object.Equals(a.JoinTest01Enum, JoinTest01Enum.f3))
 | 
				
			||||||
                .ToSql();
 | 
					                .ToSql();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -769,42 +814,6 @@ namespace base_entity
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Dictionary<string, object> dic = new Dictionary<string, object>();
 | 
					 | 
				
			||||||
            dic.Add("id", 1);
 | 
					 | 
				
			||||||
            dic.Add("name", "xxxx");
 | 
					 | 
				
			||||||
            var diclist = new List<Dictionary<string, object>>();
 | 
					 | 
				
			||||||
            diclist.Add(dic);
 | 
					 | 
				
			||||||
            diclist.Add(new Dictionary<string, object>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ["id"] = 2,
 | 
					 | 
				
			||||||
                ["name"] = "123,1234,123444"
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var sqss = fsql.InsertDict(dic).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
            var sqss2 = fsql.InsertDict(diclist).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
            sqss = fsql.InsertDict(dic).AsTable("table1").NoneParameter(false).ToSql();
 | 
					 | 
				
			||||||
            sqss2 = fsql.InsertDict(diclist).AsTable("table1").NoneParameter(false).ToSql();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var sqlupd1 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").ToSql();
 | 
					 | 
				
			||||||
            var sqlupd2 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").ToSql();
 | 
					 | 
				
			||||||
            var sqlupd11 = fsql.UpdateDict(dic).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
 | 
					 | 
				
			||||||
            var sqlupd22 = fsql.UpdateDict(diclist).AsTable("table1").WherePrimary("id").NoneParameter(false).ToSql();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var sqldel1 = fsql.DeleteDict(dic).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
            var sqldel2 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
            diclist[1]["title"] = "newtitle";
 | 
					 | 
				
			||||||
            var sqldel3 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
            diclist.Clear();
 | 
					 | 
				
			||||||
            diclist.Add(new Dictionary<string, object>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ["id"] = 1
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            diclist.Add(new Dictionary<string, object>
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ["id"] = 2
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
            var sqldel4 = fsql.DeleteDict(diclist).AsTable("table1").ToSql();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            var sql1 = fsql.Select<User1, UserGroup>()
 | 
					            var sql1 = fsql.Select<User1, UserGroup>()
 | 
				
			||||||
                .RawJoin("FULL JOIN UserGroup b ON b.id = a.GroupId")
 | 
					                .RawJoin("FULL JOIN UserGroup b ON b.id = a.GroupId")
 | 
				
			||||||
                .Where((a, b) => a.IsDeleted == false)
 | 
					                .Where((a, b) => a.IsDeleted == false)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -800,5 +800,14 @@
 | 
				
			|||||||
            <param name="that"></param>
 | 
					            <param name="that"></param>
 | 
				
			||||||
            <returns></returns>
 | 
					            <returns></returns>
 | 
				
			||||||
        </member>
 | 
					        </member>
 | 
				
			||||||
 | 
					        <member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
 | 
				
			||||||
 | 
					            <summary>
 | 
				
			||||||
 | 
					            批量注入 Repository,可以参考代码自行调整
 | 
				
			||||||
 | 
					            </summary>
 | 
				
			||||||
 | 
					            <param name="services"></param>
 | 
				
			||||||
 | 
					            <param name="globalDataFilter"></param>
 | 
				
			||||||
 | 
					            <param name="assemblies"></param>
 | 
				
			||||||
 | 
					            <returns></returns>
 | 
				
			||||||
 | 
					        </member>
 | 
				
			||||||
    </members>
 | 
					    </members>
 | 
				
			||||||
</doc>
 | 
					</doc>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -461,8 +461,10 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                var tempDict = new Dictionary<string, object>();
 | 
					                var tempDict = new Dictionary<string, object>();
 | 
				
			||||||
                foreach (var item in dicType)
 | 
					                foreach (var item in dicType)
 | 
				
			||||||
                    foreach (string key in item.Keys)
 | 
					                    foreach (string key in item.Keys)
 | 
				
			||||||
                        if (!tempDict.ContainsKey(key) && !(item[key] is null))
 | 
					                    {
 | 
				
			||||||
                            tempDict[key] = item[key];
 | 
					                        if (!tempDict.ContainsKey(key)) tempDict[key] = item[key];
 | 
				
			||||||
 | 
					                        else if (!(item[key] is null)) tempDict[key] = item[key];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(tempDict, orm, ref table);
 | 
					                UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(tempDict, orm, ref table);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user