diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderManyToMany.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderManyToMany.cs index e710bf5b6..8f8466038 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderManyToMany.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderManyToMany.cs @@ -26,12 +26,11 @@ namespace SqlSugar .Where(it => it.PropertyName != mappingA.PropertyName) .Where(it => it.PropertyName != mappingB.PropertyName) .Where(it => it.IsPrimarykey && !it.IsIdentity && it.OracleSequenceName.IsNullOrEmpty()).FirstOrDefault(); - var mappingBizDeleteColumn = mappingEntity.Columns.FirstOrDefault(it => - it.DbColumnName.EqualCase("isdelete") || - it.PropertyName.EqualCase("isdelete") || - it.DbColumnName.EqualCase("isdeleted") || - it.PropertyName.EqualCase("isdeleted") - ); + var mappingOthers = mappingEntity.Columns + .Where(it => it.PropertyName != mappingA.PropertyName) + .Where(it => it.PropertyName != mappingB.PropertyName) + .Where(it => !it.IsIdentity) + .Where(it => !it.IsPrimarykey); Check.Exception(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误"); List> mappgingTables = new List>(); foreach (var item in parentList) @@ -46,9 +45,15 @@ namespace SqlSugar Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add(mappingA.DbColumnName, parentId); keyValuePairs.Add(mappingB.DbColumnName, chidId); - if (mappingBizDeleteColumn != null) + if (mappingOthers != null) { - keyValuePairs.Add(mappingBizDeleteColumn.DbColumnName, UtilMethods.GetDefaultValue(mappingBizDeleteColumn.UnderType)); + foreach (var pair in mappingOthers) + { + if (!keyValuePairs.ContainsKey(pair.DbColumnName)) + { + keyValuePairs.Add(pair.DbColumnName, UtilMethods.GetDefaultValue(pair.UnderType)); + } + } } if (mappingPk != null) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs index eba74f07d..2d246bc08 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs @@ -26,11 +26,11 @@ namespace SqlSugar .Where(it => it.PropertyName != mappingA.PropertyName) .Where(it => it.PropertyName != mappingB.PropertyName) .Where(it => it.IsPrimarykey && !it.IsIdentity && it.OracleSequenceName.IsNullOrEmpty()).FirstOrDefault(); - var mappingBizDeleteColumn = mappingEntity.Columns.FirstOrDefault(it => - it.DbColumnName.EqualCase("isdelete") || - it.PropertyName.EqualCase("isdelete") || - it.DbColumnName.EqualCase("isdeleted") || - it.PropertyName.EqualCase("isdeleted")); + var mappingOthers = mappingEntity.Columns + .Where(it => it.PropertyName != mappingA.PropertyName) + .Where(it => it.PropertyName != mappingB.PropertyName) + .Where(it=>!it.IsIdentity) + .Where(it => !it.IsPrimarykey); Check.Exception(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误"); List> mappgingTables = new List>(); var ids=new List(); @@ -57,9 +57,15 @@ namespace SqlSugar Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add(mappingA.DbColumnName, parentId); keyValuePairs.Add(mappingB.DbColumnName, chidId); - if (mappingBizDeleteColumn != null) + if (mappingOthers != null) { - keyValuePairs.Add(mappingBizDeleteColumn.DbColumnName, UtilMethods.GetDefaultValue(mappingBizDeleteColumn.UnderType)); + foreach (var pair in mappingOthers) + { + if (!keyValuePairs.ContainsKey(pair.DbColumnName)) + { + keyValuePairs.Add(pair.DbColumnName, UtilMethods.GetDefaultValue(pair.UnderType)); + } + } } if (mappingPk != null) {