I have model named Record
which is a collection of properties from the database table and it is working fine (I display the Record collection in the html table on a page).
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new RecordConfiguration());
}
public DbSet<Record> Records { get; set; }
But now I have an requirement that also in that table I need to display additional attributes for which I don't have any foreign keys (like ManagerId or similar) and the new model looks like this
public class RecordWithManager
{
public Record Record{ get; set; }
public string ManagerFirstName { get; set; }
public string ManagerLastName { get; set; }
}
I don't want to add these new attributes to the database table and also I don't have any way how to get these data from the source table through navigation properties.
Also, I don't want to create new DTO object, which will duplicate the Records attributes and populate its data from some database view (I would have to create it), because then I would loose the navigation properties from the original Record object.
Can I somehow retrieve the Records objects and also join this object with some view (for example containing the Record.ID and new attributes) and store it to the RecordWithManager
object? I think this kind of requirement is common but I do not have simple solution for it.