diff --git a/src/NHibernate.Test/Async/QueryTranslator/CustomQueryLoaderFixture.cs b/src/NHibernate.Test/Async/QueryTranslator/CustomQueryLoaderFixture.cs
new file mode 100644
index 00000000000..67d15ddb2b4
--- /dev/null
+++ b/src/NHibernate.Test/Async/QueryTranslator/CustomQueryLoaderFixture.cs
@@ -0,0 +1,132 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by AsyncGenerator.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+
+using System.Linq;
+using NHibernate.Cfg;
+using NHibernate.DomainModel.Northwind.Entities;
+using NUnit.Framework;
+using NHibernate.Linq;
+
+namespace NHibernate.Test.QueryTranslator
+{
+ using System.Threading.Tasks;
+ [TestFixture(Description = "Tests a custom query translator factory for all query interfaces.")]
+ internal sealed class CustomQueryLoaderFixtureAsync : TestCase
+ {
+ private ISession _session;
+ private ITransaction _transaction;
+
+ protected override string[] Mappings =>
+ new[]
+ {
+ "Northwind.Mappings.Customer.hbm.xml",
+ "Northwind.Mappings.Employee.hbm.xml",
+ "Northwind.Mappings.Order.hbm.xml",
+ "Northwind.Mappings.OrderLine.hbm.xml",
+ "Northwind.Mappings.Product.hbm.xml",
+ "Northwind.Mappings.ProductCategory.hbm.xml",
+ "Northwind.Mappings.Region.hbm.xml",
+ "Northwind.Mappings.Shipper.hbm.xml",
+ "Northwind.Mappings.Supplier.hbm.xml",
+ "Northwind.Mappings.Territory.hbm.xml",
+ "Northwind.Mappings.AnotherEntity.hbm.xml",
+ "Northwind.Mappings.Role.hbm.xml",
+ "Northwind.Mappings.User.hbm.xml",
+ "Northwind.Mappings.TimeSheet.hbm.xml",
+ "Northwind.Mappings.Animal.hbm.xml",
+ "Northwind.Mappings.Patient.hbm.xml",
+ "Northwind.Mappings.NumericEntity.hbm.xml"
+ };
+
+ protected override string MappingsAssembly => "NHibernate.DomainModel";
+
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.QueryTranslator, typeof(CustomQueryTranslatorFactory).AssemblyQualifiedName);
+ }
+
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+
+ _session = OpenSession();
+ _transaction = _session.BeginTransaction();
+
+ var customer = new Customer
+ {
+ CustomerId = "C1",
+ CompanyName = "Company"
+ };
+ _session.Save(customer);
+ _session.Flush();
+ _session.Clear();
+ }
+
+ protected override void OnTearDown()
+ {
+ base.OnTearDown();
+
+ _transaction.Rollback();
+ _transaction.Dispose();
+ _session.Close();
+ _session.Dispose();
+ }
+
+ [Test(Description = "Tests criteria queries.")]
+ public async Task CriteriaQueryTestAsync()
+ {
+ var customers = await (_session.CreateCriteria(typeof(Customer))
+ .ListAsync());
+
+ Assert.That(customers.Count, Is.EqualTo(1));
+ }
+
+ [Test(Description = "Tests future queries.")]
+ public async Task FutureQueryTestAsync()
+ {
+ var futureCustomers = _session
+ .CreateQuery("select c from Customer c")
+ .Future();
+ var futureCustomersCount = _session
+ .CreateQuery("select count(*) from Customer c")
+ .FutureValue();
+
+ Assert.That(await (futureCustomersCount.GetValueAsync()), Is.EqualTo(1));
+ Assert.That(futureCustomers.ToList().Count, Is.EqualTo(await (futureCustomersCount.GetValueAsync())));
+ }
+
+ [Test(Description = "Tests HQL queries.")]
+ public async Task HqlQueryTestAsync()
+ {
+ var customers = await (_session.CreateQuery("select c from Customer c")
+ .ListAsync());
+
+ Assert.That(customers.Count, Is.EqualTo(1));
+ }
+
+ [Test(Description = "Tests LINQ queries.")]
+ public async Task LinqQueryTestAsync()
+ {
+ var customers = await (_session.Query()
+ .ToListAsync());
+
+ Assert.That(customers.Count, Is.EqualTo(1));
+ }
+
+ [Test(Description = "Tests query over queries.")]
+ public async Task QueryOverQueryTestAsync()
+ {
+ var customers = await (_session.QueryOver()
+ .ListAsync());
+
+ Assert.That(customers.Count, Is.EqualTo(1));
+ }
+ }
+}
diff --git a/src/NHibernate.Test/BulkManipulation/BaseFixture.cs b/src/NHibernate.Test/BulkManipulation/BaseFixture.cs
index 964e71dfb64..4ef6ae63bd8 100644
--- a/src/NHibernate.Test/BulkManipulation/BaseFixture.cs
+++ b/src/NHibernate.Test/BulkManipulation/BaseFixture.cs
@@ -2,6 +2,9 @@
using System.Collections;
using NHibernate.Hql.Ast.ANTLR;
using System.Collections.Generic;
+using NHibernate.Engine;
+using NHibernate.Hql.Ast.ANTLR.Tree;
+using NHibernate.Loader.Hql;
using NHibernate.Util;
namespace NHibernate.Test.BulkManipulation
@@ -34,7 +37,11 @@ protected override void Configure(Cfg.Configuration configuration)
public string GetSql(string query)
{
- var qt = new QueryTranslatorImpl(null, new HqlParseEngine(query, false, Sfi).Parse(), emptyfilters, Sfi);
+ var qt = new QueryTranslatorImpl(null,
+ new HqlParseEngine(query, false, Sfi).Parse(),
+ emptyfilters,
+ Sfi,
+ new QueryLoaderFactory());
qt.Compile(null, false);
return qt.SQLString;
}
diff --git a/src/NHibernate.Test/Hql/Ast/BaseFixture.cs b/src/NHibernate.Test/Hql/Ast/BaseFixture.cs
index cd12d32802b..a44ddd43a3a 100644
--- a/src/NHibernate.Test/Hql/Ast/BaseFixture.cs
+++ b/src/NHibernate.Test/Hql/Ast/BaseFixture.cs
@@ -1,7 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using NHibernate.Engine;
using NHibernate.Hql.Ast.ANTLR;
+using NHibernate.Hql.Ast.ANTLR.Tree;
+using NHibernate.Loader.Hql;
using NHibernate.Util;
namespace NHibernate.Test.Hql.Ast
@@ -39,7 +42,11 @@ public string GetSql(string query)
public string GetSql(string query, IDictionary replacements)
{
- var qt = new QueryTranslatorImpl(null, new HqlParseEngine(query, false, Sfi).Parse(), emptyfilters, Sfi);
+ var qt = new QueryTranslatorImpl(null,
+ new HqlParseEngine(query, false, Sfi).Parse(),
+ emptyfilters,
+ Sfi,
+ new QueryLoaderFactory());
qt.Compile(replacements, false);
return qt.SQLString;
}
diff --git a/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs b/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs
index 93f45581b30..fa76e0aa034 100644
--- a/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs
+++ b/src/NHibernate.Test/NHSpecificTest/NH2031/HqlModFuctionForMsSqlTest.cs
@@ -1,5 +1,8 @@
using NHibernate.Dialect;
+using NHibernate.Engine;
using NHibernate.Hql.Ast.ANTLR;
+using NHibernate.Hql.Ast.ANTLR.Tree;
+using NHibernate.Loader.Hql;
using NHibernate.Util;
using NUnit.Framework;
@@ -27,7 +30,11 @@ public void TheModuleOperationShouldAddParenthesisToAvoidWrongSentence()
public string GetSql(string query)
{
- var qt = new QueryTranslatorImpl(null, new HqlParseEngine(query, false, Sfi).Parse(), CollectionHelper.EmptyDictionary(), Sfi);
+ var qt = new QueryTranslatorImpl(null,
+ new HqlParseEngine(query, false, Sfi).Parse(),
+ CollectionHelper.EmptyDictionary(),
+ Sfi,
+ new QueryLoaderFactory());
qt.Compile(null, false);
return qt.SQLString;
}
diff --git a/src/NHibernate.Test/QueryTranslator/CustomQueryLoader.cs b/src/NHibernate.Test/QueryTranslator/CustomQueryLoader.cs
new file mode 100644
index 00000000000..6d072e01102
--- /dev/null
+++ b/src/NHibernate.Test/QueryTranslator/CustomQueryLoader.cs
@@ -0,0 +1,206 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Data.Common;
+using System.Threading;
+using System.Threading.Tasks;
+using NHibernate.Cache;
+using NHibernate.Engine;
+using NHibernate.Event;
+using NHibernate.Loader.Hql;
+using NHibernate.Persister;
+using NHibernate.Persister.Entity;
+using NHibernate.SqlCommand;
+using NHibernate.Transform;
+using NHibernate.Type;
+
+namespace NHibernate.Test.QueryTranslator
+{
+ ///
+ /// Custom query loader to test the functionality of custom query translator factory
+ /// with a custom query loader factory.
+ ///
+ internal sealed class CustomQueryLoader: IQueryLoader
+ {
+ private readonly IQueryLoader _queryLoader;
+
+ public CustomQueryLoader(IQueryLoader queryLoader)
+ {
+ _queryLoader = queryLoader;
+ }
+
+ public Task