table specific schema name overwriting

Posts   
 
    
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 24-Sep-2013 14:36:07   

4.0.13.523 SD.LLBLGen.Pro.DQE.SqlServer.dll 4.0.13.0725 SD.LLBLGen.Pro.ORMSupportClasses.dll 4.0.13.406 SD.LLBLGen.Pro.ORMSupportClasses.Web.dll DotNet 4.0 vs2010 project Adapter template SQL Server 2008 R2

Is it possible to optionally overwrite schema names only for tables that exist in that schema?

Sometimes I want to use a set of Entities with [dbo]. and other time [temporal]. This only on a subset of Entities (They have a distinguishing interface ITemporalized) and only when the application requires it.

I can do this in an override of CreateSelectDQ, FetchEntity and FetchEntityCollection when I have the entity available to see if it's schema needs to be rewritten, but when processing aggregates and maybe joins, then I don't think the entity is available.

I tried doing this in the override but with 60+ tables out of 160 I couldn't face writing 60 Replace lines. I might have to be satisfied with that though:-)

        protected override IRetrievalQuery CreateSelectDQ(QueryParameters parameters)
        {
            var retrievalQuery = base.CreateSelectDQ(parameters);
            if (UseTemporalViews)
            {
                var commandText = retrievalQuery.Command.CommandText;
                retrievalQuery.SetCommandText(commandText.Replace("[dbo].[v2_Topic_Base]", "[temporal].[v2_Topic_Base]"));
            }
// etc. with all the other temporal.tables
            return retrievalQuery;
        }
neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 24-Sep-2013 17:30:05   

For now I have generated an ExtensionMethod to replace [dbo].[tablename] with [temporal].[tablename] on just the tables needed. I would love a more easily to maintain approach though.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Sep-2013 22:39:00   

You can do this at the Adapter level (per instace), by setting the SchemaNameOverwrites property of the DataAccessAdapter.

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 24-Sep-2013 23:16:21   

That is too coarse grain unless I have missed a configuration setting. What if a query contains both a table I wish to use my [temporal] schema and a one that uses [dbo].

My current solution seems to work but requires re generating the extension method whenever I regenerate the adapter in case a new temporalizable table has been added. I can live with it though and it might prompt me to learn about the LLB template system.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Sep-2013 01:56:38   

What if a query contains both a table I wish to use my [temporal] schema and a one that uses [dbo].

In that case your solution might be the only way.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 25-Sep-2013 09:32:58   

neilx wrote:

That is too coarse grain unless I have missed a configuration setting. What if a query contains both a table I wish to use my [temporal] schema and a one that uses [dbo].

then you don't overwrite the schema with that adapter instance. Only overwrite the schema when temporal has to be renamed as dbo. Like Walaa described, it's per-call, so you can overwrite it before a query at an adapter instance.

Frans Bouma | Lead developer LLBLGen Pro