插入后是否可以刷新数据



我使用EF/AutoMapping。我想在插入后立即插入记录的Id(PK(。你是怎么做到的?插入后是否可以立即刷新数据?

public int InsertArtist(ArtistDto artistDto)
{
Artist entity = _mapper.Map<ArtistDto, Artist>(artistDto);
_artistRepository.Insert(entity);
_artistRepository.Save();
return entity.Id;
}

默认情况下,它正在刷新数据,假设您的Id为Database Generated,那么在保存实体后,实体框架将为该实体分配和Id,并返回引用的实体。

最新更新