I have 2 tables in my database, IncomingCheckHistory
and OutgoingCheckHistory
and there's a third table Log
that needs a unique column named HistoryId
. This number should be unique between the 2 tables (IncomingCheckHistory
and OutgoingCheckHistory
) so I can't use the checks' Id
column as the foreign key here. Also this number should be the same for 2 records per check so I can't use hte Id
from the Log
table either.
public IncomingCheckHistory()
{
public int Id { get; set; }
}
public OutgoingCheckHistory()
{
public int Id { get; set; }
}
public Log()
{
public int Id { get; set; }
public int HistoryId { get; set; } //should be unique for every 2 records
}
Is there a built-in method to generate a unique integer using Entity Framework?
If there's no such method, to me the best option seems to add fourth table, insert a record and use its Id as the value here or just generate a number based on the Id of the checks.
Clarifications:
The system uses these records to connect to an ERP system. Every check needs to have 2 records (one for the deposit account and one for the credit account) and an identifier number that should be the same for both checks (to basically connect the two) but this number shouldn't be uses for any other check.
For instance, suppose we have 2 checks, one incoming and one outgoing. IncomingCheck with Id 1 OutgoingCheck with Id 1
Now if I want to insert the respective records in Log table, I'll do this:
- Insert a record with HistoryId 1 for Id 1 (incoming) as deposit
- Insert a record with HistoryId 1 for Id 1 (incoming) as credit
- Insert a record with HistoryId 2 for Id 1 (outgoing) as deposit
- Insert a record with HistoryId 2 for Id 1 (outgoing) as credit