Csla.Blazor.ViewModel and firing specific rules on Save rather than OnModelChanging #2184
Replies: 2 comments
-
@jonnybee can probably offer the most in-depth answer. I assume you know about rule priorities, so this long-running rule only runs if the cheaper rules all succeed? Normally what I'd do, like in WPF or something, is have this particular UI control only update the business object property when the user tabs out, not on keypress. You can do that with Blazor also. This usually solves the issue and is probably the easiest answer. I know that @jonnybee added some more advanced capabilities to the rules engine, where the context includes info about why the rule is being executed. I don't recall if that allows you do tell the difference between the rule executing due to a property change vs a And that's what you are really talking about here. You'd need to override |
Beta Was this translation helpful? Give feedback.
-
There were some RunMode options to control when the rule might fire.
Alternatively, in the past I have suspended the rule by using another property to control the rule logic, and then enable it again in the Save method by un-suspending the rule and calling CheckRules manually if needed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am using the
Csla.Blazor.ViewModel
(akavm
) for myClientEdit
object on a razor page.I'm subscribing to the
ModelPropertyChanged
event on theCsla.Blazor.ViewModel
to callStateHasChanged()
this is allowing theBusinessRule
s on theClientEdit
object to fire and update the changedProperty
validation warnings, which in turn only enables theSave
button when all fields are valid based on thevm.Model.IsSavable
Property
.This is all working great.
The issue I'm facing is that one of the
BusinessRule
s I've added to theClientName
Property
isn't very lightweight as its making a database call to determine if theClientName
value already exists in the database as they are required to be unique within the application.This wouldn't be an issue except for the fact that this
BusinessRule
like the otherBusinessRule
s are being triggered on every character change (for a textbox).Is it possible to exclude certain rules so that they only get checked when the
ClientEdit
object is saved not on theModelPropertyChanged
event?Beta Was this translation helpful? Give feedback.
All reactions