c# - 插入后是否可以刷新数据?
问题描述
我使用 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 是数据库生成的,那么在保存实体后,实体框架将分配和 id 给该实体并返回引用的实体。
推荐阅读
- android - Android Espresso - 在向上滑动到列表结尾后单击带有特定字符串的第一个 RecyclerView 项目
- c# - 如何根据 C# 中的枚举值获得优势?
- firebase - 如何从 firebase 获取值并将其放入 Flutter 中的文本中
- javascript - Safari 在另一台服务器上调用 API 时拒绝 Cookie
- datamodel - Prisma 链接表不能指定任何额外的标量字段
- elasticsearch - 根据字段字符串中的单词返回文档数
- eiffel - 错误代码:VUTA(3) 错误:Object_call 的单独目标不受控制
- python - 如果 dataframe.tail(1) 是 X,做点什么
- java - SonarLint:返回一个空集合而不是 null
- oauth - 如何刷新/扩展 Azure 应用代理访问 cookie?