I’m trying to show data from two related entities in a DataGridView. I know I could just select the values like this:
from tasks in context.TaskSettings
join train in context.Trainings on tasks.TrainingID equals train.TrainingID
where tasks.TrainingID == task
select new {TrainingName = train.TrainingName,
DriversNeeded = tasks.DriversNeeded,
EmployeesPerSupervisor = tasks.EmployeesPerSupervisor};
But that gives me immutable values and my interest is showing those values in a DataGridView so the user can just edit the values and click Save Changes.
I’ve tried this other approach
ObjectQuery<TaskSetting> trainingSettings =
(ObjectQuery<TaskSetting>)context.TaskSettings.Where(t => t.TrainingID == task);
dgvTask.DataSource = trainingSettings.Execute(MergeOption.AppendOnly);
but that just puts the whole Training entity in a single column
I want to be able to, at least, get the training name from the Training entity and still be able to make changes and update the Data Context accordingly. I wanted to post pictures to be more helpful, but this is my fist question. Any help would be greatly appreciated!
Why don’t you better implement the Mediator Pattern so that you manage the internal editing by binding both entities to single properties on the Mediator. Then you bind your DataGridView to the Mediator and let it to manage the custom proper updates on the respective entities.