# Error "must be reducible node" when executing left join with LinqDataAdapter (NetStandard 2.0)

**URL:** https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345
**Category:** Data Abstract
**Tags:** net
**Created:** [May 5, 2019, 2:45am UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345 "2019-05-05T02:45:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![arturomonge](https://talk.remobjects.com/user_avatar/talk.remobjects.com/arturomonge/32/8184_2.png) [@arturomonge](https://talk.remobjects.com/u/arturomonge)
#### Post date: [May 5, 2019, 2:45am UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345/1 "2019-05-05T02:45:27Z")

</div>

Hi,

I’m getting the error “must be reducible node” when executing the following query:

```
var emailMessages = lda.GetTable<EmailMessages>();
var emailNotifications = lda.GetTable<EmailNotifications>();
var query = from e in emailMessages
				   where (e.MessageId == messageId)
				   join n in emailNotifications
						on new { Id = e.Email_Message_ID }
						equals new { Id = n.Email_Message_ID } into n1
				   from n2 in n1.DefaultIfEmpty()
				   select new { Email = e, Notifications = n2 };
var result = query.ToList();

```

This is the call stack:

```
System.ArgumentException: must be reducible node
   at System.Linq.Expressions.Expression.ReduceAndCheck()
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteNewExpression(Expression expr, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
   at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteLambdaExpression(Expression expr)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteNewExpression(Expression expr, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression expression)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteInvocationExpression(Expression expr, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteUnaryExpression(Expression expr, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpressionFreeTemps(Expression expression, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.Rewrite[T](Expression`1 lambda)
   at System.Linq.Expressions.Expression`1.Accept(StackSpiller spiller)
   at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
   at RemObjects.DataAbstract.Linq.LinqDataAdapter.FillMethod(Int32[] offsets, IDataReader reader, RequestData request, Expression expression) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\LinqDataAdapter.pas:line 875
   at RemObjects.DataAbstract.Linq.RemoteTable`1.<>c __DisplayClass0.<Execute>b__ 0(Int32 index, Int32[] offsets, IDataReader reader) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 293
   at RemObjects.DataAbstract.Linq.LinqRemoteDataAdapter.FetchData(TableRequestInfo[] tableRequest, String[] tableNames, Action`3 fillMethod) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\LinqRemoteDataAdapter.pas:line 431
   at RemObjects.DataAbstract.Linq.RemoteTable`1.Execute(Expression expression, DataParameter[] parameters) in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTable.pas:line 296
   at RemObjects.DataAbstract.Linq.RemoteTableQuery`1.GetEnumerator() in c:\CI\b\rofx\932\Data Abstract for .NET\Source\RemObjects.DataAbstract\Linq\RemoteTableQuery.pas:line 74
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   (...)

```

The project is a .NET Core 2.1 project, using the NetStandard assemblies. Is there something wrong with the LINQ statement? If I change it to an inner join, it works fine.

Thanks,  
Arturo.

---

<div class="post-metadata">

### Author: ![arturomonge](https://talk.remobjects.com/user_avatar/talk.remobjects.com/arturomonge/32/8184_2.png) [@arturomonge](https://talk.remobjects.com/u/arturomonge)
#### Post date: [May 5, 2019, 8:04pm UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345/2 "2019-05-05T20:04:21Z")

</div>

I tried the following variations, which result in the same exact query generated (the query line), but also the same error when executed (the .ToList() line):

```
var query = from e in emailMessages
				   where (e.MessageId == messageId)
				   join n in emailNotifications on e.Email_Message_ID equals n.Email_Message_ID into n1
				   from n2 in n1.DefaultIfEmpty()
				   select new { Email = e, Notifications = n2 };
var result = query.ToList();

```

and

```
var companyQuery = from e in emailMessages
				   where (e.MessageId == messageId)
				   from n in emailNotifications
						.Where(notification => notification.Email_Message_ID == e.Email_Message_ID)
						.DefaultIfEmpty()
				   select new { Email = e, Notifications = n };
var result = query.ToList();

```

So it seems to be something in DA’s LINQ processor.

Thanks,  
Arturo.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [May 6, 2019, 10:13am UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345/3 "2019-05-06T10:13:09Z")

</div>

Thanks, logged as bugs://82541

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [May 6, 2019, 10:19am UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345/4 "2019-05-06T10:19:44Z")

</div>

Well, this construction is not supported by DA LINQ (even in full .NET). Columns of the linked table have to be explicitly listed in the resulting **Select** to allow the query processor to do its job.

In other words this query will fail:

```
		var query = from o in orders
			join od in orderDetails on o.Id equals od.OrderId into oj
			from od in oj.DefaultIfEmpty()
			select new { Order = o, Details = od };

```

While this one does work:

```
		var query = from o in orders
			join od in orderDetails on o.Id equals od.OrderId into oj
			from od in oj.DefaultIfEmpty()
			select new {Order = o, Details = new OrderDetails {Id = od.Id, OrderId = od.OrderId}};

```

I’ve logged an issue, however due to the insane complexity of the DA LINQ internals I cannot promise any ETA to simplifying this (ie to allow the 1st query to work as well). Tbh at this moment I am not even sure if that is possible at all.

---

<div class="post-metadata">

### Author: ![arturomonge](https://talk.remobjects.com/user_avatar/talk.remobjects.com/arturomonge/32/8184_2.png) [@arturomonge](https://talk.remobjects.com/u/arturomonge)
#### Post date: [May 7, 2019, 8:18pm UTC](https://talk.remobjects.com/t/error-must-be-reducible-node-when-executing-left-join-with-linqdataadapter-netstandard-2-0/19345/5 "2019-05-07T20:18:38Z")

</div>

Thanks, no problem. I can use the suggested workaround when I need to do a left outer join.

Arturo.
