With the code, only the last files is added in the query list so the count of files is always 1.
How can I add all the files in the query List.
I have the following code on my page:
This is the Model for Employee:
public class Employee
{
public string Title { get; set; }
public string section { get; set; }
public string EmployeeName { get; set; }
public int employeeID { get; set; }
public List<FileModel> Files { get; set; }
}
Below is the Model for IndividualNominFilePath
public class IndividualNominFilePath
{
public int IndividualId { get; set; }
public int? EmployeeId { get; set; }
public string FilePath { get; set; }
}
In below code, I want to add FilePath in query List whenever the employeeId of IndividualNominFilePath is equal to Employee class EmployeeId
List<Employee> query = new List<Employee>();
query = await _empContext.Set<Employee>().FromSqlRaw($"EXECUTE dbo.GetIndividual").ToListAsync();
List<IndividualNominFilePath> individualNominFiles = _empContext.IndividualNominFilePaths.ToList();
foreach (var item in query)
{
foreach (var file in individualNominFiles)
{
if (file.EmployeeId == item.EmployeeID)
{
item.Files = new List<FileModel>()
{
new FileModel {EmployeeNumber=file.EmployeeId,FilePath=file.UploadedFilePath }
};
}
}
}