修复 .From 多表查询别名的匹配 bug

This commit is contained in:
28810
2019-07-17 18:01:52 +08:00
parent a5f524d154
commit 558d154486
2 changed files with 29 additions and 2 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace FreeSql.Internal
{
@ -341,6 +342,7 @@ namespace FreeSql.Internal
return GetBoolString(sql);
return sql;
}
static ConcurrentDictionary<string, Regex> dicRegexAlias = new ConcurrentDictionary<string, Regex>();
public void ExpressionJoinLambda(List<SelectTableInfo> _tables, SelectTableInfoType tbtype, Expression exp, Func<Expression[], string> getSelectGroupingMapString)
{
var tbidx = _tables.Count;
@ -360,7 +362,10 @@ namespace FreeSql.Internal
}
else
{
var find = _tables.Where((a, c) => c > 0 && (a.Type == tbtype || a.Type == SelectTableInfoType.From) && string.IsNullOrEmpty(a.On) && sql.Contains(a.Alias + ".")).LastOrDefault();
var find = _tables.Where((a, c) => c > 0 &&
(a.Type == tbtype || a.Type == SelectTableInfoType.From) &&
string.IsNullOrEmpty(a.On) &&
dicRegexAlias.GetOrAdd(a.Alias, alias => new Regex($@"\b{alias}\.", RegexOptions.Compiled)).IsMatch(sql)).LastOrDefault();
if (find != null)
{
find.Type = tbtype;