create DTO class from method parameters
Opened this issue · 3 comments
i have many functions in interface implemntaion, i want to create a webapi controler with one parameter as a dto class
there is a way to select multiple params from a function/method and convert it to new dto class ?
for example:
public async Task<List<students_QueryByDetailsResult>> SP_students_QueryByDetails(string PName, string Fname, string ParentPName, string ParentFname, double? student_id, double? parent_id, byte? Part, byte? @class, int? StudyYear, int? IncludeLeftStudents, int? UD_index1, int? UD_value1, int? UD_index2, int? UD_value2)
{
var result = await _context.Procedures.students_QueryByDetailsAsync(PName, Fname, ParentPName, ParentFname, student_id, parent_id, Part, @class, StudyYear, IncludeLeftStudents, UD_index1, UD_value1, UD_index2, UD_value2);
return result;
}
i want to copy all this params in function to new class like:
public class ClassDTO
{
string PName { get; set; }
string Fname { get; set; }
string ParentPName { get; set; }
string ParentFname { get; set; }
double? student_id { get; set; }
double? parent_id { get; set; }
byte? Part { get; set; }
byte? @class { get; set; }
int? StudyYear { get; set; }
int? IncludeLeftStudents { get; set; }
int? UD_index1 { get; set; }
int? UD_value1 { get; set; }
int? UD_index2 { get; set; }
int? UD_value2 { get; set; }
}
im using efCore powertools to generate function to all my stored procedures from the database, and my SPs have alot of paramaters ... i looking to use it like a dto class from POST API
To automatically generate class properties based on the method parameters you need to
- Create an empty target class (ClassDTO)
- Set
Unmapped sources to
Generate missing propertiesin the
Matching` tab of MappingGenerator setts
MippingGenerator should automatically add missing properties matching method parameters
thank you , but i want to generate new dto class and it will replace all the parameters in the method ... it's not same returned class
somthing like:
public async Task<List<students_QueryByDetailsResult>> SP_students_QueryByDetails(**ClassDTO data**)
{
var result = await _context.Procedures.students_QueryByDetailsAsync(data.PName, data.Fname, data.ParentPName, data.ParentFname, data.student_id, data.parent_id, data.Part, data.@class, data.StudyYear, data.IncludeLeftStudents, data.UD_index1,data. UD_value1, data.data.UD_index2, data.UD_value2);
return result;
}