I have a class Employee with many properties in it and when I want to read it from the database and return a list of it. I want to add an extra field to it.
Currently it's like this:
return await _context.Employees.ToListAsync();
I don't want to use Select command after Employee because as far as I know I have to list all my properties in the Employee class to be able to add an extra one like below:
return await _context.Employees.Select(em => new
{
em.Firstname, // In employee class
em.Lastname, // In employee class
... // Other properties in employee class
EXTRAFIELD = "Data" // Extra field with any data I want to add to employee
}).ToListAsync();
But in the solution above I have to list all my fields in employee class.
I don't want to do as below as it puts employee in a new object names em:
return await _context.Employees.Select(em => new
{
em,
EXTRAFIELD = "Data" // Extra field with any data I want to add to employee
}).ToListAsync();
Is there a way to tell DbContext (_context) to return Employee fields and add "this new field" in it (create new object which has same properties as Employee with one extra)?