小编Ani*_*Ali的帖子

使用dapper插入一个到多个实体

我有以下两个类和相应的数据库表.我试图插入完整的对象图(学生有多个课程).我正在寻找一个如何使用Dapper来做这个的例子.Id是自动增量标识字段.

public class Student
{
    public int Id {get;set;}
    public string Name {get;set;}
    public IEnumerable<Course> Courses {get;set;}
}
public class Course
{
    public int Id {get;set;}
    public string Name {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

学生
  ID [int](pk)
  姓名[varchar(50)]

StudentCourse
  StudentId [int](fk)
  CourseId [int](fk)

课程
  ID [int](fk)
  姓名[varchar(50)]

.net sql insert one-to-many dapper

10
推荐指数
1
解决办法
6896
查看次数

如何使用dapper一起选择一对多关系和一对一

我有以下类和数据库模式.我试图使用dapper从数据库中查询这些数据,这将使整个对象图水合.我查看了各种SO问题和测试,但无法弄清楚如何做到这一点.

DB Schema

Author
  -AuthorId
  -Name

Post
  -PostId
  -Content
  -AuthorId

Comment
  -PostId
  -CommentId
  -Content

Tag
  -PostId
  -TagId
  -Name
Run Code Online (Sandbox Code Playgroud)

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; …
Run Code Online (Sandbox Code Playgroud)

select one-to-one one-to-many dapper

5
推荐指数
1
解决办法
3693
查看次数

标签 统计

dapper ×2

one-to-many ×2

.net ×1

insert ×1

one-to-one ×1

select ×1

sql ×1