我有以下类和数据库模式。我正在尝试使用 dapper 从数据库中查询这些数据,这将水合完整的对象图。我查看了各种 SO 问题和测试,但无法真正弄清楚如何做到这一点。
数据库架构
Author
-AuthorId
-Name
Post
-PostId
-Content
-AuthorId
Comment
-PostId
-CommentId
-Content
Tag
-PostId
-TagId
-Name
课程
public class Author
{
public int AuthorId { get; set; }
public string Name { get; set; }
}
public class Tag
{
public int PostId { get; set; }
public int TagId { get; set; }
public string Name { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Content { get; set; }
public int AuthorId { get; set; }
public List<Tag> Tags { get; set; }
public List<Comment> Comments { get; set; }
public Author Author { get; set; }
public Post()
{
this.Comments = new List<Comment>();
this.Tags = new List<Tag>();
}
}
public class Comment
{
public int PostId { get; set; }
public int CommentId { get; set; }
public string Content { get; set; }
}