User-1950145079 posted
I want to query a list of person from the database and in the table, it has a column that also contains a list of relatives which is another table in the database. Will this line of code solve the problem? Will it produce a performance issue in the future
with thousands of data?
Refer to the code below:
public class Employee
{
public int Id { get; set; }
public string Name{ get; set; }
public virtual List<Relatives> { get; set; }
}
public class Relatives
{
public int Id { get; set; }
public string Name{ get; set; }
public int EmployeeId { get; set; }
[ForeignKey("EmployeeId")]
public virtual Employee Employee { get; set; }
}
var list = GetDbSet<Employee>().Select(x => new
{
id = x.Id,
name = x.Name,
ListOfRelatives = string.Join(",", (x.Relatives.Where(y => y.EmployeeId == x.Id).Select(z => z.Name)))
}.ToList();