我有带有输入和输出参数的存储过程。我有单独的输入和输出类。所以,我想使用模板对象创建动态参数,而不是添加每个属性。
例如:
public class StudentInput {
public StudentInput() {
this.StudentId = 1;
}
public int StudentId {get; set}
}
public class StudentOutput {
public string StudentName {get; set;}
public string FavSubject {get; set;}
public int Grade {get; set;}
public int YearOfJoining {get; set;}
}
我有一个[SP_GetStudentData]
以 StudentId 作为输入并返回 StudentName、FavSubject、Grade 和 YearOfJoining 的存储过程。
使用 Dapper,我编写了以下代码。
DynamicParameters ip = new DynamicParameters(new StudentInput());
DynamicParameters op = new DynamicParameters(new StudentOutput());
ip.AddDynamicParameters(op);
//Here is the question. How do I tell Dapper that op is a output parameters object? How do I add ParameterDirection output to each of the properties in this object?
SqlMapper.ExecuteSP(connection, SP_GetStudentData, ip, CommandType.StoredProcedure)