Hi there,
I am still trying the .NET version of DA compared to the Delphi one.
In Delphi, there are the Strongly-Typed datatable interfaces/classes that were generated (SchemaClient_Intf), along with the server-side delta commands (SchemaServer_Intf). This allowed one to write custom Business Rule classes that would be used both on client AND server to validate modifications on data.
For example, if I write a custom class
TMyAddressBusinessRule = class(TAddressBusinessRule, IAddress)
...
TMyAddressBusinessRule.BeforeInsert(...)
begin
// validate something
end;
That class would be both usable by server and client. (Maybe I am mistaken).
I am not talking about the Javascript business-rule scripting capability. The problem I have with the javascript business rule system is
- You have no code completion
- No compile-time errors, only runtime-errors.
3, Not easy access to other C# / Pascal classes
This is why I prefer to use C# or Pascal business rules. This way, you have a strongly typed language and can have code-completion and compile-time errors. I know that because of this, I am limiting the target platform.
I understood how to use the custom business rule classes in Delphi. We have to inherit from the generated business rule class, then register the class with RegisterBusinessRule(Class, ID);
But, I can’t seem to find this concept on .NET with LINQ.
What I’ve found so far :
1. LINQ table definitions.
Those are partial classes that can be extended to add perhaps methods or additional properties.
But, these table definitions, to my knowledge, are
- Not used on the server-side (maybe I’m mistaken)
- Not used for validation of data
2. Business rule processors
Those would be the equivalent of delphi Business Processors.
Though, those are, to my knowledge
- Not used on the client side
- Cannot use the LINQ classes with easy property access.
For #2, in Delphi, the BusinessProessorRules inherited from an interface (Strongly-Typed interface generation). Like TAddressBusinessRule = class(TDABusinessRule, IAddress)
. This allowed to have code-completion for the business rule like :
TAddressBusinessRule.OnProcessChange(...)
begin
Self.Field1 = "ABC" and Self.Field2 = "DEF";
end
But in .NET, you do not have this kind of code completion, and you must write
private void BusinessProcessor_BeforeProcessChange(BusinessProcessor sender, DeltaChangeEventArgs e)
{
if (e.DeltaChange.Type == RemObjects.DataAbstract.ChangeType.Insert)
{
string table = sender.ReferencedDataTable;
e.DeltaChange.NewValues[0] = e.DeltaChange.OldValues[0];
}
}
You lose all the fluent Self.Field1 property accessors, and must use some weird index-based property accessors to access the business rules. There must be an easier way?
My question is, how is it possible to easily define business rules that will be either
- usable by the server
- usable by the client and the server
AND
- that would be written in C# using the great and easy to use LINQ table definitions ?
For example, a user that is not a employee with the “special” flag cannot insert a new client.
For example, a client cannot be inserted if it’s name has not been provided.
For example, a user cannot modify the parameters table records.
I would like to define these business rules in one place, and it would be enforced both on client and server. Is that supported in C# ?