Composite Key and Value Attribution

According to the help the "For composite id's this value is
ignored and None is used." in case of TIdGenerator.

I will be using always a primary key for all tables that is Domain (string 10) + ID (GUID)

I want to populate this information automatically. In my MVP model, I am using the AureliusDataSet on the View to make easier. I know it have events I could add that value. 

But I have a lot of other code that is in the Model and will create these entities and depend also to have them initialized. The Domain is a Global value, and the ID is a GUID.

Since there is no Manager Events, My question is: 

Could I make each entity inherit from a common base class where the create method set default value for both Domain and ID?

Of course the FDomain and FID variable member will be in the base class, but the property with the tag COLUMN will be on the child class. 

If it is a NEW record/class the value will be already set, but in case of a record being retrieved the default value will be lost (sure it is not needed). It is there for the case of new record anyways.

Is it valid for Aurelius?

Yes, you can do that. Note that using assigned generator (None) you lose some features. For example, SaveOrUpdate method doesn't work, because Aurelius will always consider you are updating the object (because Id is already set) although you might have objects you want to save (insert) instead.

I strongly recommend not using composite id's in Aurelius. Since you already have a GUID, why adding Domain field to primary key? You could just keep Domain property in table for later reference (and merging, which is I suppose you want to do) or even create a secondary index of that.

very strong point you mentioned....

Many thanks for the so valuable information, that is letting me to integrate Aurelius really fast on my source code. 

I am creating a multi-tenant database. 

Each table can be unique or shared to other companies in the same software, depending on the Domain attribution. 

Sure I prefer using the TidGenerator.GUID case.

I want that Domain to be always considered for everything, as a "global" filter, can this be done? What is the suggest approach for that since for all the queries I need to consider the Domain as a condition? 

I know that TAureliusDataset has the filter option, however my Model Layer already creates a ICriteriaCursor pre defined since it creates a live database connection that makes easy to take advantage on the RAD part of Delphi. The view is totally design based, no coding! Thanks to the TAureliusDataset. Fantastic.

However to select a Domain by using projection it will not generate a live query that can be updated by TAureliusDataset. 


Hi Eduardo, not sure if I understand what you mean.

There is no such concept of global filter in Aurelius, but as you said yourself, since it helps in object-oriented programming, you can just create a TCriteria and add a Domain filter in that criteria somehow, for example passing the TCriteria object to a global method that adds default filter. But I'm not sure how it relates to the TDataset? You will always have to add the Domain value manually to be sure the record you insert will belong to a specific Domain.

Right now I am using TAureliusDataset.SetSourceCursor as a way to navigate on the Criteria made by my model layer and gets the benefits of a live query on the view. Right?

Using Fetch-On-Demand

"Note that the advantage of this approach is that it keeps an active
connection and an active query to the database until all records are fetched (or
dataset is closed)."

following the help example:


  Cursor: ICriteriaCursor;


  Cursor := Manager.Find<TPerson>.Open;


How can I add a filter condition (in this case for the Domain property) to this ICriteriaCursor keeping the benefit of active connection with the database?

The Find method returns a TCriteria object. The example just uses fluent interface to get the cursor directly, but you can just do this:

  Criteria: TCriteria;
  Cursor: ICriteriaCurrsor;
  Criteria := Manager.Find<TPerson>;
  // for example: Criteria.Add(TLinq.Eq('Domain', 2));
  Cursor := Criteria.Open;
  // now pass the cursor to the dataset