0

I work with EF / AutoMapping. And I want after an Insert immediately the Id (PK) of the record. How do you do that? Is it possible refreshing the data immediately after an insert?

public int InsertArtist(ArtistDto artistDto)
{
    Artist entity = _mapper.Map<ArtistDto, Artist>(artistDto);

    _artistRepository.Insert(entity);
    _artistRepository.Save();

    return entity.Id;
}
atiyar
  • 7,762
  • 6
  • 34
  • 75
user1531040
  • 2,143
  • 6
  • 28
  • 48

1 Answers1

0

By default it is refreshing the data, suppose your Id is Database Generated, then after saving the entity, entity framework will assign and id to that entity and will return the referenced one.