mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 14:04:44 +08:00
Table filter support append on
This commit is contained in:
parent
bfc99eb334
commit
6ff16c284e
@ -23,8 +23,9 @@ namespace OrmTest
|
||||
{
|
||||
var db = GetInstance();
|
||||
//Order add filter
|
||||
db.QueryFilter.Add(new TableFilterItem<Order>(it => it.Name.Contains("a")));
|
||||
db.QueryFilter.Add(new TableFilterItem<Order>(it => it.Name.Contains("a"),true));
|
||||
|
||||
db.Queryable<Order>().ToList();
|
||||
|
||||
db.Queryable<Order>().ToList();
|
||||
//SELECT [Id],[Name],[Price],[CreateTime],[CustomId] FROM [Order] WHERE ([Name] like '%'+@MethodConst0+'%')
|
||||
@ -40,6 +41,8 @@ namespace OrmTest
|
||||
//no filter
|
||||
db.Queryable<Order>().Filter(null, false).ToList();
|
||||
//SELECT [Id],[Name],[Price],[CreateTime],[CustomId] FROM [Order]
|
||||
|
||||
db.Queryable<OrderItem>().LeftJoin<Order>((x, y) => x.ItemId == y.Id).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -384,7 +384,24 @@ namespace SqlSugar
|
||||
sql = GetSql(exp, isSingle);
|
||||
sql = sql.Replace(itName, shortName);
|
||||
}
|
||||
WhereInfos.Add(sql);
|
||||
if (item.IsJoinQuery == false||isMain||isSingle|| isEasyJoin)
|
||||
{
|
||||
WhereInfos.Add(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var joinInfo in this.JoinQueryInfos)
|
||||
{
|
||||
if (joinInfo.TableName.EqualCase(entityInfo.EntityName)|| joinInfo.TableName.EqualCase(entityInfo.DbTableName))
|
||||
{
|
||||
if (sql.StartsWith(" WHERE "))
|
||||
{
|
||||
sql = Regex.Replace(sql, $"^ WHERE ", " AND ");
|
||||
}
|
||||
joinInfo.JoinWhere=joinInfo.JoinWhere + sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSql(Expression exp, bool isSingle)
|
||||
|
@ -27,16 +27,19 @@ namespace SqlSugar
|
||||
}
|
||||
private Expression exp { get; set; }
|
||||
private Type type { get; set; }
|
||||
public TableFilterItem(Expression<Func<T,bool>> expression)
|
||||
public TableFilterItem(Expression<Func<T,bool>> expression,bool isJoinOn=false)
|
||||
{
|
||||
exp = expression;
|
||||
type = typeof(T);
|
||||
base.IsJoinQuery = isJoinOn;
|
||||
this.IsJoinQuery = isJoinOn;
|
||||
}
|
||||
|
||||
public TableFilterItem(Type entityType,Expression expression)
|
||||
public TableFilterItem(Type entityType,Expression expression, bool isJoinOn=false)
|
||||
{
|
||||
exp = expression;
|
||||
type = entityType;
|
||||
IsJoinQuery = isJoinOn;
|
||||
}
|
||||
|
||||
private new string FilterName { get; set; }
|
||||
|
Loading…
Reference in New Issue
Block a user