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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:58:55+00:00 2026-05-14T05:58:55+00:00

Does anyone have a simple example of implementing an async validation rule in csla?

  • 0

Does anyone have a simple example of implementing an async validation rule in csla?

I have looked at the example in the Company class in the Rolodex sample but this isn’t particularly clear to me: why do I need a command class?

I’m using csla 3.8 in a WPF application.

  • 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-14T05:58:55+00:00Added an answer on May 14, 2026 at 5:58 am

    OK I figured out how to do this, but in the end it turned out that the answer opened a rather large can of worms.

    Adding the Async rule to your business class:

    protected override void AddBusinessRules()
    {
        base.AddBusinessRules();
    
        ValidationRules.AddRule(UserNameIsUniqueAsync, new AsyncRuleArgs(UserRefProperty, NameProperty));
    }
    

    The first arg for AddRule is a delegate shown below:

    private static void UserNameIsUniqueAsync(AsyncValidationRuleContext context)
    {
        DuplicateUserNameCommand command = new DuplicateUserNameCommand((int)context.PropertyValues["UserRef"], context.PropertyValues["Name"].ToString());
        DataPortal<DuplicateUserNameCommand> dp = new DataPortal<DuplicateUserNameCommand>();
    
        dp.ExecuteCompleted += (o, e) =>
        {
            if (e.Error != null)
            {
                context.OutArgs.Description = "Error checking for duplicate user name.  " + e.Error.ToString();
                context.OutArgs.Severity = RuleSeverity.Error;
                context.OutArgs.Result = false;
            }
            else
            {
                if (e.Object.IsDuplicate)
                {
                    context.OutArgs.Description = "Duplicate user name.";
                    context.OutArgs.Severity = RuleSeverity.Error;
                    context.OutArgs.Result = false;
                }
                else
                {
                    context.OutArgs.Result = true;
                }
            }
    
            context.Complete();
            System.Diagnostics.Debug.WriteLine("Context.Complete()");
        };
        dp.BeginExecute(command);
    }
    

    The delegate in turn calls a DuplicateUserNameCommand which is new type you need to create:

    [Serializable]
    public class DuplicateUserNameCommand : CommandBase
    {
        private int _userRef;
        private string _userName;
        private bool _isDuplicate;
    
        public DuplicateUserNameCommand(int userRef, string userName)
        {
            _userRef = userRef;
            _userName = userName;
        }
    
        public bool IsDuplicate
        {
            get { return _isDuplicate; }
            private set { _isDuplicate = value; }
        }
    
    
        protected override void DataPortal_Execute()
        {
            // Check for an existing user in the database with the same username
            var repository = new NHibernateUserDAORepository();
            var existingUser = repository.FindByUserName(_userName);
    
            if (existingUser != null && existingUser.UserRef != _userRef)
            {
                _isDuplicate = true;
            }
            else
            {
                _isDuplicate = false;
            }
        }
    }
    

    That’s about it. The problem that I encountered is that all the code in Command’s DataPortal_Execute needs to be thread safe. In my case this caused severak issues so for now I’m reverting back to synchronous rules.

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

Sidebar

Ask A Question

Stats

  • Questions 352k
  • Answers 352k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, first you need to save those variables somewhere, like… May 14, 2026 at 7:31 am
  • Editorial Team
    Editorial Team added an answer [[NSTimeZone localTimeZone] secondsFromGMT] / 3600 May 14, 2026 at 7:31 am
  • Editorial Team
    Editorial Team added an answer Where did you try Activate()? I found that using it… May 14, 2026 at 7:31 am

Related Questions

I have a Windows service that runs implementations of a framework across multiple threads.
I'm really interested in speech-to-text algorithms, but I'm not sure where to start studying
Let's say I want to create a collection class that is thread-safe by default.
I was wondering if anyone had any suggestions for minimizing a function, f(x,y), where
Does anyone have a process or approach to use for determining how to resove

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.