How to share C# business rules between client and server

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

  1. You have no code completion
  2. 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

  1. Not used on the server-side (maybe I’m mistaken)
  2. 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

  1. Not used on the client side
  2. 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

  1. usable by the server
  2. usable by the client and the server

AND

  1. 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# ?

No, this is not supported on .NET platform. Actually in most cases server and client apps cannot share the code due to the different platforms they run on (f.e. .NET server and Delphi client etc), so they need to implement and perform their checks separately.

Also for example in a .NET application DataAbstract-related code should belong to the Data Access Layer while data checks should be performed by the Domain Layer.

And to define server-only business rules, can we use the linq table definitions in the business processors ?

The main purpose of the Table Definition classes is to materialize results of data requests. So if you need to query some data this can be done via LinqLocalDataAdapter and these classes will be used.