Skip to content

Commit

Permalink
- fix 1.5.0-preview0502 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed May 8, 2020
1 parent d69db2a commit 03a9488
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 41 deletions.
16 changes: 0 additions & 16 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,20 @@ public void Test02()

g.sqlite.GlobalFilter.Apply<gf_t1>("gft1", a => a.rowstate > -1 && g.sqlite.Select<gf_t2>().Any(b => b.id == a.id))
.Apply<gf_t2>("gft2", a => a.rowstate > -2)
.Apply<gf_t3>("gft3", a => a.rowstate > -3);
.Apply<gf_t3>("gft3", a => a.rowstate > -3)
.Apply<gf_t1>("gft11", a => a.rowstate > -1);

var tksk1 = g.sqlite.Select<gf_t1, gf_t2, gf_t3>()
.InnerJoin((a, b, c) => a.id == b.id)
.Where((a, b, c) => c.rowstate > 10)
.ToList();
g.sqlite.Update<gf_t1>().NoneParameter().Set(a => a.rowstate + 1).Where(a => a.rowstate >= 0).ExecuteAffrows();

var tksk2 = g.sqlite.Select<gf_t1, gf_t2, gf_t3>()
.InnerJoin((a, b, c) => a.id == b.id)
.Where((a, b, c) => c.rowstate > 10)
.ToList();
g.sqlite.Update<gf_t1>().NoneParameter().Set(a => a.rowstate + 1).Where(a => a.rowstate >= 0).ExecuteAffrows();

var dtot2 = g.sqlite.Select<gf_t1>().ToList(a => new gfDto
{
Expand Down
15 changes: 9 additions & 6 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,8 @@ public ExpTSC CloneDisableDiyParse()
}
}

static ConcurrentDictionary<string, bool> _dicGetWhereCascadeSqlError = new ConcurrentDictionary<string, bool>();
public string GetWhereCascadeSql(SelectTableInfo tb, List<LambdaExpression> _whereCascadeExpression)
static ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicGetWhereCascadeSqlError = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
public string GetWhereCascadeSql(SelectTableInfo tb, List<LambdaExpression> _whereCascadeExpression, bool isMultitb)
{
if (_whereCascadeExpression.Any())
{
Expand All @@ -1445,8 +1445,9 @@ public string GetWhereCascadeSql(SelectTableInfo tb, List<LambdaExpression> _whe

foreach (var fl in _whereCascadeExpression)
{
var errorKey = FreeUtil.Sha1($"{tb.Table.Type.FullName},{fl.ToString()}");
if (_dicGetWhereCascadeSqlError.ContainsKey(errorKey)) continue;
var dicSqlError = _dicGetWhereCascadeSqlError.GetOrAdd(tb.Table.Type, tp => new ConcurrentDictionary<string, bool>());
var errorKey = FreeUtil.Sha1($"{(isMultitb ? 1 : 0)},{fl.ToString()}");
if (dicSqlError.ContainsKey(errorKey)) continue;

var visitor = new ReplaceVisitor();
try
Expand All @@ -1456,7 +1457,9 @@ public string GetWhereCascadeSql(SelectTableInfo tb, List<LambdaExpression> _whe
new ReplaceVisitor().Modify(fl, newParameter),
newParameter
);
var whereSql = ExpressionLambdaToSql(expExp.Body, new ExpTSC { _tables = new List<SelectTableInfo>(new[] { tb }), _selectColumnMap = null, getSelectGroupingMapString = null, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, currentTable = tb.Table, alias001 = tb.Alias });
var whereSql = ExpressionLambdaToSql(expExp.Body, new ExpTSC { _tables =
isMultitb ? new List<SelectTableInfo>(new[] { tb }) : null,
_selectColumnMap = null, getSelectGroupingMapString = null, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, currentTable = tb.Table, alias001 = tb.Alias });
whereSql = GetBoolString(expExp.Body, whereSql);
if (isEmpty == false)
sb.Append(" AND ");
Expand All @@ -1466,7 +1469,7 @@ public string GetWhereCascadeSql(SelectTableInfo tb, List<LambdaExpression> _whe
}
catch
{
_dicGetWhereCascadeSqlError.TryAdd(errorKey, true);
dicSqlError.TryAdd(errorKey, true);
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Internal/CommonProvider/DeleteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public string ToSql()

if (_whereGlobalFilter.Any())
{
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter.Select(a => a.Where).ToList());
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter.Select(a => a.Where).ToList(), false);
if (string.IsNullOrEmpty(globalFilterCondi) == false)
sb.Append(" AND ").Append(globalFilterCondi);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public ISelect<T1> IncludeMany<TNavigate>(Expression<Func<T1, IEnumerable<TNavig
sbJoin.Append($"midtb.{_commonUtils.QuoteSqlName(tbref.MiddleColumns[tbref.Columns.Count + z].Attribute.Name)} = a.{_commonUtils.QuoteSqlName(tbref.RefColumns[z].Attribute.Name)}");
if (_whereCascadeExpression.Any())
{
var cascade = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Alias = "midtb", AliasInit = "midtb", Table = tbrefMid, Type = SelectTableInfoType.InnerJoin }, _whereCascadeExpression);
var cascade = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Alias = "midtb", AliasInit = "midtb", Table = tbrefMid, Type = SelectTableInfoType.InnerJoin }, _whereCascadeExpression, true);
if (string.IsNullOrEmpty(cascade) == false)
sbJoin.Append(" AND (").Append(cascade).Append(")");
}
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Internal/CommonProvider/UpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ public string ToSql()

if (_whereGlobalFilter.Any())
{
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter.Select(a => a.Where).ToList());
var globalFilterCondi = _commonExpression.GetWhereCascadeSql(new SelectTableInfo { Table = _table }, _whereGlobalFilter.Select(a => a.Where).ToList(), false);
if (string.IsNullOrEmpty(globalFilterCondi) == false)
sb.Append(" AND ").Append(globalFilterCondi);
}
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Dameng/Curd/DamengSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MsAccess/Curd/MsAccessSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MySql/Curd/MySqlSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Odbc/Default/Curd/OdbcSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, CommonExpr

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down Expand Up @@ -140,7 +140,7 @@ internal static string ToSqlStaticOffsetFetchNext(CommonUtils _commonUtils, Comm

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Oracle/Curd/OracleSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
4 changes: 2 additions & 2 deletions Providers/FreeSql.Provider.SqlServer/Curd/SqlServerSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, CommonExpr

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down Expand Up @@ -140,7 +140,7 @@ internal static string ToSqlStaticOffsetFetchNext(CommonUtils _commonUtils, Comm

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Sqlite/Curd/SqliteSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static string ToSqlStatic(CommonUtils _commonUtils, CommonExpression _c

if (_whereCascadeExpression.Any())
foreach (var tb in _tables.Where(a => a.Type != SelectTableInfoType.Parent))
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression);
tb.Cascade = _commonExpression.GetWhereCascadeSql(tb, _whereCascadeExpression, true);

var sb = new StringBuilder();
var tbUnionsGt0 = tbUnions.Count > 1;
Expand Down

0 comments on commit 03a9488

Please sign in to comment.