Dear hikalkan, Thank you for quick response. i will check and in case of any issue, will get back to you.
The code is from domain service, hence used actual entity rather than dto.
regards Shailesh
thanks for your tip, i will work on it. regards Shailesh
public async Task UpdateAsync(Guard guard)
{
//Guard updateGuard = Guard.Create
//(guard.SiteId,guard.GuardNo,guard.GuardName,guard.CardNo,guard.IsActive,guard.Id);
//Guard _guard = await GetGuardUsingGuardNoAsync(updateGuard.GuardNo);
//if (_guard != null && _guard.Id != updateGuard.Id)
// throw new UserFriendlyException("Guard No. already Exists!");
//_guard = await GetGuardUsingCardNoAsync(guard.CardNo);
//if (_guard != null && _guard.Id != guard.Id)
// throw new UserFriendlyException("Card No. already Exists!");
await _guardRepository.UpdateAsync(guard);
}
if i uncomment the code and run it, then while saving entity i get : System.InvalidOperationException: Attaching an entity of type 'GTMS.Domain.Guard' failed because another entity of the same type already has the same primary key value.
here primary key is ID and it is autonumber.
Commented Code checks for duplication of field value. with above coding, software can update the entity, but when uncommented, it gives above error. regards Shailesh