Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6630005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:20:30+00:00 2026-05-25T22:20:30+00:00

We are using Castle ActiveRecord as a helper layer on top of NHibernate. To

  • 0

We are using Castle ActiveRecord as a helper layer on top of NHibernate. To generate our database, we use:

ActiveRecordStarter.CreateSchema();

To generate the sql for building our database we use:

ActiveRecordStarter.GenerateCreationScripts(filename);

They work like a charm. However we sometimes don’t want to generate a table for every one of our entities. I believe nhibernate has a mechanism for excluding certain tables from a schema build (see here) – does anyone know whether ActiveRecord can do the same thing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:20:30+00:00Added an answer on May 25, 2026 at 10:20 pm

    For posterity, here’s what I ended up doing:

    1) Grabbed the NHibernate SchemaExporter source code and renamed the class to “OurSchemaExporter”.

    2) Added a new constructor:

        public OurSchemaExporter(Configuration cfg, Func<string, bool> shouldScriptBeIncluded)
            : this(cfg, cfg.Properties)
        {
            this.shouldScriptBeIncluded = shouldScriptBeIncluded ?? (s => true);
        }
    

    3) Modified the initialize method to call out to find out whether a script should be included:

        private void Initialize()
        {
            if (this.wasInitialized)
                return;
            if (PropertiesHelper.GetString("hbm2ddl.keywords", this.configProperties, "not-defined").ToLowerInvariant() == Hbm2DDLKeyWords.AutoQuote)
                SchemaMetadataUpdater.QuoteTableAndColumns(this.cfg);
            this.dialect = Dialect.GetDialect(this.configProperties);
            this.dropSQL = this.cfg.GenerateDropSchemaScript(this.dialect);
            this.createSQL = this.cfg.GenerateSchemaCreationScript(this.dialect);
    
            // ** our modification to exclude certain scripts **
            this.dropSQL = new string[0]; // we handle the drops ourselves, as NH doesn't know the names of all our FKs
            this.createSQL = this.createSQL.Where(s => shouldScriptBeIncluded(s)).ToArray();
    
            this.formatter = (PropertiesHelper.GetBoolean("format_sql", this.configProperties, true) ? FormatStyle.Ddl : FormatStyle.None).Formatter;
            this.wasInitialized = true;
        }
    

    4) When using OurSchemaExporter, check whether we want to include certain tables by looking at the contents of each SQL create script:

    var ourSchemaExport = new TpsSchemaExporter(configuration, ShouldScriptBeIncluded);
    
    ...
    
    private bool ShouldScriptBeIncluded(string script)
    {
      return !tablesToSkip.Any(t => ShouldSkip(script, t));
    }
    
    private static bool ShouldSkip(string script, string tableName)
    {
      string s = script.ToLower();
      string t = tableName.ToLower();
      return
        s.Contains(string.Format("create table dbo.{0} ", t))
        || s.Contains(string.Format("alter table dbo.{0} ", t))
        || s.EndsWith(string.Format("drop table dbo.{0}", t));
    }
    

    A hack, but it does the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume you are using some libraries like NHibernate or Castle ActiveRecord that use log4net
Using Castle ActiveRecord / NHibernate: Is there a way you can force an ICriterion
I'm using ASP.Net MVC (still 1.0 for now) with Castle ActiveRecord and NHibernate.Linq. All
I'm using ASP.NET MVC with Castle ActiveRecord as my persistance layer. I want to
I'm using Castle ActiveRecord which uses NHibernate underneath and I've added a property with
I'm using Castle ActiveRecord, but this question applies to NHibernate, too, since a solution
I'm going to refactor a growing project from using Castle Activerecord to pure NHibernate
I started using nhibernate the same time I started using castle activerecord so I
I'm trying to delete all rows in a table using Castle ActiveRecord. Normally, I
for my current project I am using Castle's ActiveRecord in C#. For one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.