Yes. I do this all the time. The rule uses a BO (like a command object) to return a result.When the rule is added I set the priority to 1 - the default priority is zero for all "simple rules". This means that the rule that hits the DB does not run unless all the simple rules are passed first.
But that may not be what you are asking...
Hmm. I would consider adding a flag to the BO which tells it if it is just a "standard" IsValid call or the "special" call that precedes a Save. By setting the flag to false initially, the rule can check it and skip over the DB rule and always return True. Then when you are ready to do a real save, your Save button code sets the flag to true and now when you check IsValid the DB rule will actually run for the first time. (And only time if everything is really valid.) You might also consider skipping over the framework call to IsValid so it doesn't run a 2nd time during the .Save method. I forget if there is an overload in the framework that does this or whether I added it to my base class.
Joe
Patrick:
is it possible to define rules which only run on the server side?
E.g. sometimes a rule might need to "talk" to the database and do quite a few queries to verify that it (the rule) is valid. Naturally I would only want to run this rule just before persisting the entity and not on every IsValid request on the client.
I do not think this is possible in 3.6. I could offer a
hack thought :- )
You can use ApplicationContext.LocalContext.Contans(SomeSpecialKey)
and set the key say as part of user login on the client (or some other place
during startup). The same value will never be set on the server, so you
have a stable check for execution location. Not as nice of a solution as
you propose, but is should work.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Patrick
[mailto:cslanet@lhotka.net]
Sent: Tuesday, October 07, 2008 5:14 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Broken Rules - Client / Server
Patrick:
is it possible to define rules which only run on the server side?
E.g. sometimes a rule might need to "talk" to the database and do quite a few queries to verify that it (the rule) is valid. Naturally I would only want to run this rule just before persisting the entity and not on every IsValid request on the client.
Just a follow-up to ask if this is possible with CSLA.NET 3.6 at the moment.
Thanks,
Patrick
Copyright (c) Marimer LLC