I want to get the list of data from the database as student each student has list of projects
public class Student
{
public int StudentId { get; set; }
public string StudentName{ get; set; }
public List
}
public class Project
{
public int ProjectId { get; set; }
public string ProjectName { get; set; }
}

Tahir AnsariRank #366 · 6.8K reputationPosted Apr 6, 2024, 3:29 AM EDT
using System; using System.Linq; class Program { static void Main(string[] args) { using (var context = new YourDbContext()) { var studentsWithProjects = context.Students .FromSqlRaw("EXEC dbo.GetStudentsWithProjects") // Assuming "GetStudentsWithProjects" is your stored procedure name .ToList(); foreach (var student in studentsWithProjects) { Console.WriteLine($"Student ID: {student.StudentId}, Name: {student.StudentName}"); foreach (var project in student.Projects) { Console.WriteLine($" Project ID: {project.ProjectId}, Name: {project.ProjectName}"); } } } } }Jaimin ShethiyaRank #177 · 13.7K reputationPosted Apr 6, 2024, 11:50 PM EDT
Hello,
In your example the relationship is not there, so you need to first do the relationship then after create the store procedure to get the combine data.
Thanks