Browse Source

Synchronization code

master
sunkaixuan 1 year ago
parent
commit
37b1464280
  1. 6
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  2. 1
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  3. 18
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

6
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -379,16 +379,18 @@ namespace SqlSugar
this.ClearFilter(typeof(FilterType1), typeof(FilterType2),typeof(FilterType3)); this.ClearFilter(typeof(FilterType1), typeof(FilterType2),typeof(FilterType3));
return this; return this;
} }
public ISugarQueryable<T> Filter(Type type) public ISugarQueryable<T> Filter(Type type)
{ {
this.Context.InitMappingInfo(type); this.Context.InitMappingInfo(type);
var whereString= QueryBuilder.GetFilters(type); var whereString= QueryBuilder.GetFilters(type);
if (whereString.HasValue()) if (whereString.HasValue())
{ {
this.Where(whereString); this.Where(whereString);
} }
UtilMethods.AddDiscrimator(type,this);
return this; return this;
} }
public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction) public virtual ISugarQueryable<T> Mapper(Action<T> mapperAction)
{ {
this.MapperAction=UtilMethods.IsNullReturnNew(this.MapperAction); this.MapperAction=UtilMethods.IsNullReturnNew(this.MapperAction);

1
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -127,6 +127,7 @@ namespace SqlSugar
InitMappingInfo<T>(); InitMappingInfo<T>();
var result = this.CreateQueryable<T>(); var result = this.CreateQueryable<T>();
UtilMethods.AddDiscrimator(typeof(T), result);
return result; return result;
} }
/// <summary> /// <summary>

18
Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

@ -1265,5 +1265,23 @@ namespace SqlSugar
var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString"); var method = value.GetType().GetMethods().First(it => it.GetParameters().Length == 0 && it.Name == "ToShortDateString");
return method.Invoke(value, new object[] { }); return method.Invoke(value, new object[] { });
} }
internal static void AddDiscrimator<T>(Type type, ISugarQueryable<T> 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);
}
}
}
} }
} }

Loading…
Cancel
Save