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 3721834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:41:30+00:00 2026-05-19T05:41:30+00:00

Is there a way to disable Active Record validation for an nhibernate session /

  • 0

Is there a way to disable Active Record validation for an nhibernate session / active record scope?

I have a scenario whereby we are performing deletion of a large number of items – and in some cases customers have data in their database that will not pass validation (it was captured prior to new validation rules being introduced, or due to manual manipulation of the database etc.)

When deleting, due the way the database is constructed, some validation checks on existing entities occur, and fail with an exception – preventing the deletion of those entities.

For the deletion scenario we would like to disable all validation from occurring associated with the transaction/session/scope the entities are being deleted within, is this possible?

Update 23/01/2011

Implemented a simple validation active record base class for disabling validation:

public class DisabledValidationProvider : IValidationProvider
{
    public bool IsValid()
    {
        return true;
    }

    public bool IsValid(RunWhen runWhen)
    {
        return true;
    }

    public string[] ValidationErrorMessages
    {
        get { return null; }
    }

    public IDictionary PropertiesValidationErrorMessages
    {
        get { return null; }
    }
}

public class DisableValidationScope : IDisposable
{
    public DisableValidationScope()
    {
        Local.Data["DisableValidationScope"] = true;
    }

    public static bool IsValidationDisabled
    {
        get { return Local.Data["DisableValidationScope"] != null; }
    }

    public void Dispose()
    {
        Local.Data["DisableValidationScope"] = null;
    }
}

public abstract class ScopeAwareValidationBase : ActiveRecordHooksValidationBase
{
    static readonly IValidationProvider DisabledProvider = new DisabledValidationProvider();

    protected override IValidationProvider ActualValidator
    {
        get
        {
            if (DisableValidationScope.IsValidationDisabled)
            {
                return DisabledProvider;
            }
            return base.ActualValidator;
        }
    }
}

My ActiveRecord models inherit from ScopeAwareValidationBase and then I can just emplot a using statement around my transaction code, works a treat.

using (new DisableValidationScope()) 
{
    // do transactional 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-19T05:41:31+00:00Added an answer on May 19, 2026 at 5:41 am

    I’d look into overriding the ActualValidator property, there you could either:

    • provide a setter, to let your code decide whether to apply validation or not on a per-instance basis, or
    • (better) look up some context associated to the current SessionScope that decides whether to apply validation or not.

    To disable validation, you’d return a dummy IValidationProvider that always returned true to IsValid(), etc.

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

Sidebar

Related Questions

Is there a way to disable entering multi-line entries in a Text Box (i.e.,
Is there a way to disable LINQ's object tracking features, without also disabling lazy-loaded
Is there a way to disable Intellisense in the XAML editor in Visual Studio
Is there a way to disable or override the excel and pdf export function
Is there a way to disable a tab in a TabControl ?
You know the one I mean: Is there a way to disable this? I'm
Rails caches (file cache) per default domain-based, but is there a way to disable
Is there a way to programmatically disable usb storage devices from working while still
I would like to know if there is a way to disable automatic loading
Is there a way to set a pragma disable warning for visual studio for

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.