I recently started implementing the IIdGenerator interface as I need pritty advanced id-generation. There are some rules I'm forced to follow when creating this, as the database is shared with some old software systems written in C++ and more. Unfortunately I'm not allowed to change the database using GUID or autoincrements. Let me simplify things by explaining a general example. Let us say we have two tabels defined such:
tableA
int idA // primary key
varchar(50) aName
tableB
int idA // partial primary key and foreighn key to tableA
int idB // partial primary key
varchar(50) bName
As you se, the primary key of tableB is made up by two integers where the first one is a foreighn key to tableA.
The rules are such whenever I create an entry in tableB, idB has to increment from one (1). Example
TableA
idA = 1
TableB
idA = 1
idB = 1 (for the first record under TableA.idA=1)
idB = 2 (for the second record under TableA.idA=1)
idB = 3 (for the third record under TableA.idA=1)
TableA
idA = 2
TableB
idA = 2
idB = 1 (for the first record under TableA.idA=2)
idB = 2 (for the second record under TableA.idA=2)
So I allways have to stard idB from 1 in TableB, for each new record in TableA
The problem is how can I in the server side call to
public
UniqueIdMap GetRealIdMap(UniqueIdCollection tempIds, IDataSourceKey dataSourceKey)
find out for what idA it is called when requesting real Id for for TableB.idB? If I had that information it would be easy for my to request a valid idB from the database in GetRealIdMap. But without it I can't.
Second question is If I add entities to TableA as well as TableB and then perform save (both eintities with temporary Ids) is it guranteed that the TableA entity is saved first before calling GetRealIdMap for the TableB entity so that I know the real idA at that time...or is it all done in one call to GetRealIdMap?