It seems there is a fundamental problem with the way the Object manager works when used in a multi-threaded application: if use the following code, i'm getting "Duplicate key values not allowed" even though all object instances are unique to the thread:
var
ObjectManager: TObjectManager;
begin
ObjectManager:= GetAureliusOM(ConnectionString); // this creates new instances of Connection, IDBConnection and TObjectManager
try
AFile := ObjectManager.Find<Tt_files>(FileID);
...
TargetFolder := FindTargetFolder(
AFile.f_user_ID.u_expert_ID.e_target_folder,
AFile.f_user_ID.u_private_dir.ValueOrDefault,
AFile.f_company.ValueOrDefault);
AFile is an entity with the f_user_ID being a foreign key:
[Entity]
[Table('t_files')]
[Id('Ff_ID', TIdGenerator.IdentityOrSequence)]
Tt_files = class
private
[Column('f_ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
Ff_ID: Integer;
...
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('f_user_ID', [TColumnProp.Required], 'u_ID')]
Ff_user_ID: Proxy<Tt_users>;
function Getf_user_ID: Tt_users;
procedure Setf_user_ID(const Value: Tt_users);
Apparently, for reasons that aren't clear to me, I'm getting almost constant "Duplicate key is not allowed" when hitting that code from a second thread. The duplicate object is the Tt_users instance (the two t_Files different row reference the same t_Users row)
I have no idea how to solve this.