using System.Collections.Generic;
public string studentName {get; set;}
public int idCourse {get; set;}
public int id {get; set;}
public string courseName {get; set;}
public ICollection<Student> Students {get; set;} = new List<Student>();
public string courseNameDTO {get; set;}
public List<string> StudentsFromDTO {get; set;}
public class CourseFactory
public static Course FromDTO(CourseDTO dto)
Course createdCourse = new () { courseName = dto.courseNameDTO };
dto.StudentsFromDTO.ForEach(name => createdCourse.Students.Add(new() { idCourse = createdCourse.id, studentName = name }));
public static void Main()
courseNameDTO = "course name dto",
var course = CourseFactory.FromDTO(dto);
Console.WriteLine("Created {0}:", course);
Console.WriteLine(JsonSerializer.Serialize(course, new JsonSerializerOptions { WriteIndented = true }));