I have a TasksDbContext
for my Tasks
table where each task has a user identified by a UserId
field, but the Users
table is in a different database and is managed by a different team’s UsersDbContext
. Is there a way to populate the task’s UserName
property in my DbContext without stepping on the other team’s toes with regards to datamigrations etc.?
I would prefer to avoid looping through the tasks and getting the user name for each individual item by using the other team’s UsersDbContext
.
public class TasksDbContext : DbContext
{
public DbSet<Task> Tasks { get; set; } = default!
public TasksDbContext (DbContextOptions<TasksDbContext > options)
: base(options)
{
}
}
public class Task
{
[Key]
public int Id { get; set; }
public string UserId { get; set; }
[NotMapped]
public string UserName { get; set; } // Stored in the other Users table.
public string Text { get; set; }
public bool Done { get; set; }
}