简体   繁体   中英

Is it possible to refresh the data after insert?

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM