Hi guys,
I am querying a table. If the GUID is empty in the table, I am generating new GUID and update the table. But as soon as I update and SaveAsync, the generated GUID changes interestingly. Why does it happen?
I am querying a table. If the GUID is empty in the table, I am generating new GUID and update the table. But as soon as I update and SaveAsync, the generated GUID changes interestingly. Why does it happen?
C#:
...
//Unique reference ID
gameRequest.referenceId = Guid.NewGuid(); --> generates the GUID
var gameRequestDto = iMapper.Map<GameRequest, GameRequestDto>(gameRequest);
//Create signature
gameRequest = Utilities.CreateSignature(gameRequestDto, RequestType.Initiate);
//Add initiation request into database
_unitOfWork.GameRepository.Insert(gameRequest);
//Query GameBank database
var gameBankResult =
await _unitOfWork.GameBankRepository.GetGamesAsync(g =>
g.productCode == requestDto.productCode && g.referenceId == Guid.Empty);
//If we have exact number of games in our database, mark them!
if (gameBankResult.Count() != 0 && gameBankResult.Count() >= requestDto.quantity)
{
for (var index = 0; index < requestDto.quantity; index++)
{
var item = gameBankResult[index];
item.referenceId = gameRequest.referenceId; --> sets the GUID, so far no problem
item.requestDateTime = DateTime.Now;
item.responseDateTime = DateTime.Now;
_unitOfWork.GameBankRepository.Update(item);
await _unitOfWork.SaveAsync(); --> GUID changes after this
}
//Query GameBank database
var gameBankConfirmResult =
await _unitOfWork.GameBankRepository.GetGamesAsync(g =>
g.referenceId == gameRequest.referenceId); --> different GUID so no results returns
if (gameBankConfirmResult != null)
{
if (gameBankConfirmResult.Count == 1)
{
...