Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Calling stored procedure with output parameter from a Rule

$
0
0
Hello,

Thank you for making such an awesome framework. I have an odd requirement where I need to call out to a stored proc (via EF) passing in an output parameter (or two). I need to validate the response of this. I want to do this via the fluent / RuleFor logic, but am not seeing a straight forward approach.

It looks like it might need some nested Func<T>'s but here is the gist of the logic

This is my standard validation logic
var outputParameter = new System.Data.Entity.Core.Objects.ObjectParameter("isUnique", typeof(bool));

            databaseContext_validate_unique_name(description, outputParameter);
            if (outputParameter.Value != null)
            {
                if ((bool)outputParameter.Value == false)
                {
                    //throw exception as the name is not unique
                    throw new ArgumentException(ErrorMessages.NameIsNotUnique());
                }
            }
I was trying something like so
  RuleFor(category => category.Description)
            .Must(description => "1".Equals("call Sproc from here and get output variable?"))
            .WithMessage("Error: description must be unique!");
        
Any help would be greatly appreciated.

Thanks,

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>