据我所知Dapper
可以处理多个结果集和多个映射,但现在我有一个不同的情况,它强制我在SQL数据库中执行存储过程,其中包含3个JOIN
查询。因此,这意味着我需要使用Dapper ORM来执行该存储过程,该存储过程将同时执行两个操作(多个结果+多个映射)。
SQL查询:
SELECT *
FROM Departments D
JOIN Employees E ON D.Id = E.Department
SELECT *
FROM Classes C
LEFT JOIN Students S ON C.Id = S.ClassId
SELECT *
FROM Users
WHERE Id = @UserId
映射模型类:
class Department
{
public int Id { get; set; }
public string Name { get; set; }
public List<Employee> Employees { get; set; }
}
class Employee
{
public int Id { get; set; }
public string Name{ get; set; }
public int DepartmentId { get; set; }
}
class Class
{
public int Id { get; set; }
public string Title { get; set; }
public List<Student> Students { get; set; }
}
class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int ClassId { get; set; }
}
class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}