question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database do not support CROSS/OUTER APPLY join required by the query

See original GitHub issue

Hi Guys,

I’m targeting SQLite - instead of SQL Server - in my unit test, and the following query results in an error:

var qrecalls =
    from ra in dbContext.Every<RecareAvailability>()

    join rt in dbContext.Every<RecareType>() on ra.RecareTypeId equals rt.Id

    join p in dbContext.Every<Patient>() on ra.PatientId equals p.Id

    join si in dbContext.Every<ScheduleItem>() on ra.AppointmentId equals si.Id into sis
    from si in sis.Take(1).DefaultIfEmpty()

    orderby p.Id

    select new Recall
    {
    };

Please note sis.Take(1) - this is the cause of the error.

I’m wondering if there is a workaround, or if not, if the issue can be fixed by generating an SQL with an operation that is alternative to APPLY.

Much appreciated

Iouri

linq2db 2.5.2 (.net core)

Result StackTrace:	
at LinqToDB.SqlQuery.SelectQueryOptimizer.OptimizeApply(HashSet`1 parentTableSources, SqlTableSource tableSource, SqlJoinedTable joinTable, Boolean isApplySupported, Boolean optimizeColumns) in C:\projects\linq2db\Source\LinqToDB\SqlQuery\SelectQueryOptimizer.cs:line 930
   at LinqToDB.SqlQuery.SelectQueryOptimizer.OptimizeApplies(Boolean isApplySupported, Boolean optimizeColumns) in C:\projects\linq2db\Source\LinqToDB\SqlQuery\SelectQueryOptimizer.cs:line 1032
   at LinqToDB.SqlQuery.SelectQueryOptimizer.FinalizeAndValidateInternal(Boolean isApplySupported, Boolean optimizeColumns, List`1 tables) in C:\projects\linq2db\Source\LinqToDB\SqlQuery\SelectQueryOptimizer.cs:line 418
   at LinqToDB.SqlQuery.SelectQueryOptimizer.FinalizeAndValidate(Boolean isApplySupported, Boolean optimizeColumns) in C:\projects\linq2db\Source\LinqToDB\SqlQuery\SelectQueryOptimizer.cs:line 46
   at LinqToDB.SqlProvider.BasicSqlOptimizer.<>c__DisplayClass4_0.<Finalize>b__0(SelectQuery selectQuery) in C:\projects\linq2db\Source\LinqToDB\SqlProvider\BasicSqlOptimizer.cs:line 41
   at LinqToDB.SqlQuery.SqlStatementWithQueryBase.WalkQueries(Func`2 func) in C:\projects\linq2db\Source\LinqToDB\SqlQuery\SqlStatementWithQueryBase.cs:line 39
   at LinqToDB.SqlProvider.BasicSqlOptimizer.Finalize(SqlStatement statement) in C:\projects\linq2db\Source\LinqToDB\SqlProvider\BasicSqlOptimizer.cs:line 45
   at LinqToDB.DataProvider.SQLite.SQLiteSqlOptimizer.Finalize(SqlStatement statement) in C:\projects\linq2db\Source\LinqToDB\DataProvider\SQLite\SQLiteSqlOptimizer.cs:line 18
   at LinqToDB.Linq.QueryRunner.FinalizeQuery(Query query) in C:\projects\linq2db\Source\LinqToDB\Linq\QueryRunner.cs:line 109
   at LinqToDB.Linq.QueryRunner.GetExecuteQuery[T](Query query, Func`7 queryFunc) in C:\projects\linq2db\Source\LinqToDB\Linq\QueryRunner.cs:line 262
   at LinqToDB.Linq.QueryRunner.SetRunQuery[T](Query`1 query, Expression`1 expression) in C:\projects\linq2db\Source\LinqToDB\Linq\QueryRunner.cs:line 522
   at LinqToDB.Linq.Builder.ExpressionBuilder.Build[T]() in C:\projects\linq2db\Source\LinqToDB\Linq\Builder\ExpressionBuilder.cs:line 161
   at LinqToDB.Linq.Query`1.CreateQuery(IDataContext dataContext, Expression expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 269
   at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:line 233
   at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 84
   at LinqToDB.Linq.ExpressionQuery`1.System.Collections.IEnumerable.GetEnumerator() in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:line 188
   at Linquifier.LinquifiableQuery.GetEnumerator() in G:\soe\ascend-api\linquifier\LinquifiableQuery.cs:line 56
   at Linquifier.LinquifiableQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() in G:\soe\ascend-api\linquifier\LinquifiableQuery.cs:line 116
   at System.Linq.Enumerable.TakeWhileIterator[TSource](IEnumerable`1 source, Func`2 predicate)+MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at LinqToDB.AsyncExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken token) in C:\projects\linq2db\Source\LinqToDB\AsyncExtensions.cs:line 151
   
--- End of stack trace from previous location where exception was thrown ---

Result Message:	LinqToDB.LinqToDBException : Database do not support CROSS/OUTER APPLY join required by the query.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iouriscommented, Nov 26, 2018

@MaceWindu - please ignore my previous comment.

I’ve managed to get it working by following https://github.com/aspnet/Microsoft.Data.Sqlite/issues/526, see comment from bricelam.

0reactions
sdanylivcommented, Nov 27, 2018

@iouris, closing as answered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server CROSS APPLY and OUTER APPLY
In this tip I am going to demonstrate the SQL Sever CROSS APPLY and OUTER APPLY and how they differ from regular JOINs...
Read more >
how solve the OUTER APPLY is not supported problem in ...
im using LINQ to Entities with dotConnect for Oracle and i get an OUTER APPLY is not supported exception with this very simple...
Read more >
The Difference between CROSS APPLY and OUTER ...
SQL Server supports table valued functions, what are functions ... The CROSS APPLY operator is semantically similar to INNER JOIN operator.
Read more >
CROSS APPLY produces outer join - sql server
The outer join arises when the optimizer transforms an apply to a join (using a rule called ApplyHandler ) to see if it...
Read more >
SQL Cross Apply and Outer Apply: The Complete Guide
It lets you join a table to a “table-valued function”, or to join to a subquery that refers to the outer query for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found