From d80b53e9b28fb6fb6e9fcad8a970a2450e5d361b Mon Sep 17 00:00:00 2001 From: Lau Date: Sat, 2 May 2020 14:37:57 +0200 Subject: [PATCH] Fix join statement generation. --- .../Sql/Internal/JetQuerySqlGenerator.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs index 75b5268..445f1b4 100644 --- a/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs +++ b/src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs @@ -106,34 +106,44 @@ namespace EntityFrameworkCore.Jet.Query.Sql.Internal Sql.Append( new string( - '(', Math.Max( - 0, selectExpression + '(', + Math.Max( + 0, + selectExpression .Tables .Count(t => !(t is CrossJoinExpression || t is CrossApplyExpression)) - maxTablesWithoutBrackets))); for (var index = 0; index < selectExpression.Tables.Count; index++) { var tableExpression = selectExpression.Tables[index]; + + var isApplyExpression = tableExpression is CrossApplyExpression || + tableExpression is OuterApplyExpression; + var isCrossExpression = tableExpression is CrossJoinExpression || tableExpression is CrossApplyExpression; + if (isApplyExpression) + { + throw new InvalidOperationException("Jet does not support APPLY statements. Switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync() if needed."); + } + if (index > 0) { if (isCrossExpression) { Sql.Append(","); } + else if (index >= maxTablesWithoutBrackets && + index < selectExpression.Tables.Count - 1) + { + Sql.Append(")"); + } Sql.AppendLine(); } Visit(tableExpression); - - if (!isCrossExpression && - index >= maxTablesWithoutBrackets) - { - Sql.Append(")"); - } } } else