diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 397826948..5bb155719 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -379,16 +379,18 @@ namespace SqlSugar this.ClearFilter(typeof(FilterType1), typeof(FilterType2),typeof(FilterType3)); return this; } - public ISugarQueryable Filter(Type type) + public ISugarQueryable Filter(Type type) { this.Context.InitMappingInfo(type); var whereString= QueryBuilder.GetFilters(type); - if (whereString.HasValue()) + if (whereString.HasValue()) { this.Where(whereString); } + UtilMethods.AddDiscrimator(type,this); return this; } + public virtual ISugarQueryable Mapper(Action mapperAction) { this.MapperAction=UtilMethods.IsNullReturnNew(this.MapperAction); diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs index 668f0647a..44fcd214b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs @@ -127,6 +127,7 @@ namespace SqlSugar InitMappingInfo(); var result = this.CreateQueryable(); + UtilMethods.AddDiscrimator(typeof(T), result); return result; } /// diff --git a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs index 03e702399..fb7320fab 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs @@ -1265,5 +1265,23 @@ namespace SqlSugar var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString"); return method.Invoke(value, new object[] { }); } + + + internal static void AddDiscrimator(Type type, ISugarQueryable queryable) + { + var entityInfo = queryable.Context?.EntityMaintenance?.GetEntityInfoWithAttr(type); + if (entityInfo!=null&&entityInfo.Discrimator.HasValue()) + { + Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式,如果是多个可以FieldName:cat,FieldName2:dog,不要有空格"); + var array = entityInfo.Discrimator.Split(','); + foreach (var disItem in array) + { + var name = disItem.Split(':').First(); + var value = disItem.Split(':').Last(); + queryable.Where(name, "=", value); + } + } + } + } }