entity-framework-core - 使用 AutoMapper 在 Entity Framework Core 中进行多对一映射
问题描述
我有两个模型类来获取包含全名的评论列表:
public partial class Comment
{
public int Id { get; set; }
public string Comment{ get; set; }
public int? AddBy{ get; set; }
public virtual User { get; set; }
}
public partial class User
{
public int Id { get; set; }
public string FullName { get; set; }
public virtual ICollection<Comment> Comments{ get; set; }
}
这是我的评论 Dto
public partial class CommentDto
{
public int Id { get; set; }
public string Comment { get; set; }
public string FullName { get; set; }
}
我的查询选择了所有带有用户(全名)的评论,但包含在未给出用户模型的映射器中
CreateMap<Comment, CommentDto>()
.ForMember(x => x.FullName, opt => opt.MapFrom(x => x
解决方案
推荐阅读
- r - 一个简单的“paste0”命令在“draw”命令中不起作用?(复杂热图,r)
- python - Python运行外部可执行文件
- symfony - Symfony:实体关联
- excel - 如何将一行值连接成一个单一的文本字符串?
- c++ - 如何将具有相同名称的继承函数视为重载函数?
- node.js - 无法使用 SES/Lambda 发送电子邮件,但代码适用于容器
- unicode - 如何从#defined 的 ascii 字符串初始化 WCHAR 字符串。不包括 L 前缀
- java - SQLite 语法错误,但语句完全正确
- r - SMA 计算不正确的问题
- powershell - 如何为算术表达式构建 AST 树?