- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
5.9 & .Net 6: Alter/Modify Generated SQL
Joined: 05-Oct-2017
Build Version 5.9 (5.9.2) RTM Build Date: 24-May-2022 Project: Adapter project targeting .NET 6 Database: MS SQL on 2016
Hi!
In a previous post I asked about ways to override or modify the SQL LLBLGen Pro generated before the query was sent to the database. Your answer was that we could override the CreateSelectDQ method (on DataAccessAdapterCore) on our data access adapter implementation.
We've recently started the move to .net 6 and it looks like that method isn't available to override anymore. Is there another option we can take to achieve similar functionality?
Thanks!
Previous Post: https://www.llblgen.com/tinyforum/Thread/27441
Joined: 17-Aug-2003
In v5.9 we refactored a lot of code into its separate class indeed. Here's an equivalent which does what you want, so it's a bit similar but requires a separate class
public class CommandTrackingQueryCreationManager : QueryCreationManager
{
public CommandTrackingQueryCreationManager(DataAccessAdapterCore containingAdapter, IPersistenceInfoProvider persistenceInfoProvider)
: base(containingAdapter, persistenceInfoProvider)
{}
protected override IRetrievalQuery CreateSelectDQ(QueryParameters parameters)
{
if(this.GeneratedCommands == null)
{
this.GeneratedCommands = new List<DbCommand>();
}
var toReturn = base.CreateSelectDQ(parameters);
this.GeneratedCommands.Add(toReturn.Command);
return toReturn;
}
public List<DbCommand> GeneratedCommands { get; private set; }
}
public class TemporalTableTestDataAccessAdapter : Sql2016Adapter
{
private CommandTrackingQueryCreationManager _queryCreationManager;
/// <summary>CTor</summary>
public TemporalTableTestDataAccessAdapter()
{
}
/// <summary>CTor</summary>
/// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
public TemporalTableTestDataAccessAdapter(bool keepConnectionOpen) : base(keepConnectionOpen)
{
}
/// <summary>CTor</summary>
/// <param name="connectionString">The connection string to use when connecting to the database.</param>
public TemporalTableTestDataAccessAdapter(string connectionString) : base(connectionString)
{
}
/// <summary>CTor</summary>
/// <param name="connectionString">The connection string to use when connecting to the database.</param>
/// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
public TemporalTableTestDataAccessAdapter(string connectionString, bool keepConnectionOpen) : base(connectionString, keepConnectionOpen)
{
}
/// <summary>CTor.</summary>
/// <param name="connectionString">The connection string to use when connecting to the database.</param>
/// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
/// <param name="catalogNameUsageSetting"> Configures this data access adapter object how to threat catalog names in persistence information.</param>
/// <param name="catalogNameToUse"> The name to use if catalogNameUsageSetting is set to ForceName. Ignored otherwise.</param>
/// <remarks>For backwards compatibility.</remarks>
public TemporalTableTestDataAccessAdapter(string connectionString, bool keepConnectionOpen, CatalogNameUsage catalogNameUsageSetting, string catalogNameToUse) : base(connectionString, keepConnectionOpen, catalogNameUsageSetting, catalogNameToUse)
{
}
/// <summary>CTor</summary>
/// <param name="connectionString">The connection string to use when connecting to the database.</param>
/// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
/// <param name="schemaNameUsageSetting">Configures this data access adapter object how to threat schema names in persistence information.</param>
/// <param name="schemaNameToUse">Oracle specific. The name to use if schemaNameUsageSetting is set to ForceName. Ignored otherwise.</param>
public TemporalTableTestDataAccessAdapter(string connectionString, bool keepConnectionOpen, SchemaNameUsage schemaNameUsageSetting, string schemaNameToUse) : base(connectionString, keepConnectionOpen, schemaNameUsageSetting, schemaNameToUse)
{
}
/// <summary>CTor.</summary>
/// <param name="connectionString">The connection string to use when connecting to the database.</param>
/// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
/// <param name="catalogNameOverwrites"> The from-to name value pairs and setting for the overwriting of catalog names. Can be null.</param>
/// <param name="schemaNameOverwrites"> The from-to name value pairs and setting for the overwriting of schema names. Can be null.</param>
public TemporalTableTestDataAccessAdapter(string connectionString, bool keepConnectionOpen, CatalogNameOverwriteHashtable catalogNameOverwrites, SchemaNameOverwriteHashtable schemaNameOverwrites) : base(connectionString, keepConnectionOpen, catalogNameOverwrites, schemaNameOverwrites)
{
}
protected override QueryCreationManager CreateQueryCreationManager(IPersistenceInfoProvider persistenceInfoProvider)
{
_queryCreationManager = new CommandTrackingQueryCreationManager(this, persistenceInfoProvider);
return _queryCreationManager;
}
/// <summary>
/// Gets the last generated command.
/// </summary>
public DbCommand LastGeneratedCommand
{
get
{
if(_queryCreationManager.GeneratedCommands == null)
{
return null;
}
return _queryCreationManager.GeneratedCommands.Last();
}
}
public List<DbCommand> GeneratedCommands => _queryCreationManager.GeneratedCommands;
}