Describe your issue.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Exception message:Index was out of range. Must be non-negative and less than the size of the collection.
Stack trace:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at LinqToDB.SqlProvider.BasicSqlOptimizer.<>c.<FixSetOperationNulls>b__7_0(IQueryElement e)
at LinqToDB.SqlQuery.QueryParentVisitor`1.Visit(IQueryElement element)
at LinqToDB.SqlQuery.QueryParentVisitor`1.VisitX(SqlTableSource table)
at LinqToDB.SqlQuery.QueryParentVisitor`1.Visit(IQueryElement element)
at LinqToDB.SqlQuery.QueryParentVisitor`1.VisitX(SqlFromClause element)
at LinqToDB.SqlQuery.QueryParentVisitor`1.Visit(IQueryElement element)
at LinqToDB.SqlQuery.QueryParentVisitor`1.VisitX(SelectQuery q)
at LinqToDB.SqlQuery.QueryParentVisitor`1.Visit(IQueryElement element)
at LinqToDB.SqlQuery.QueryParentVisitor`1.Visit(IQueryElement element)
at LinqToDB.SqlProvider.BasicSqlOptimizer.FixSetOperationNulls(SqlStatement statement)
at LinqToDB.SqlProvider.BasicSqlOptimizer.Finalize(SqlStatement statement)
at LinqToDB.Linq.QueryRunner.FinalizeQuery(Query query)
at LinqToDB.Linq.QueryRunner.GetExecuteQuery[T](Query query, Func`8 queryFunc)
at LinqToDB.Linq.QueryRunner.SetRunQuery[T](Query`1 query, Expression`1 expression)
at LinqToDB.Linq.Builder.ExpressionBuilder.Build[T]()
at LinqToDB.Linq.Query`1.CreateQuery(ExpressionTreeOptimizationContext optimizationContext, ParametersContext parametersContext, IDataContext dataContext, Expression expr)
at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr, Boolean& dependsOnParameters)
at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache, Boolean& dependsOnParameters)
at LinqToDB.Linq.ExpressionQuery`1.GetForEachAsync(Action`1 action, CancellationToken cancellationToken)
at LinqToDB.AsyncExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken token)
Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
using LinqToDB;
using LinqToDB.Data;
using LinqToDB.DataProvider.Oracle;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace LinqToDBTest
{
public class MyModel
{
public string ID { get; set; }
public string COLA { get; set; }
}
internal class Program
{
static async Task Main(string[] args)
{
try
{
using (var conn = new DataConnection(ProviderName.MySqlConnector, ""))
{
var q1 = from x in conn.GetTable<MyModel>()
where x.ID == "aaa"
select new
{
x.ID,
COLA = "A",
OK = x.COLA == "123" ? "Y" : "N",
};
var q2 = from x in conn.GetTable<MyModel>()
where x.ID == "bbb"
select new
{
x.ID,
x.COLA,
OK = "N"
};
//var query = q1.UnionAll(q2);
var query = q1.Union(q2);
var q3 = from x in query
from y in conn.GetTable<MyModel>().LeftJoin(t => t.ID == x.ID)
where x.ID == "ccc"
select new
{
x.ID,
x.OK,
COLA = x.COLA == "ddd" ? y.COLA : x.COLA,
};
var list = await q3.ToListAsync();
Console.WriteLine(list.Count);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
Environment details
linq2db version: 4.1.1
Database Server: any
Database Provider: any
Operating system: Windows
.NET Framework: .net6/.net4.8
Describe your issue.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
Environment details
linq2db version: 4.1.1
Database Server: any
Database Provider: any
Operating system: Windows
.NET Framework: .net6/.net4.8