Consider the following model…
DataModel

I’ve a WCF data Service (PMService) that exposes the datamodels to my JobsViewModel
WCF Data Service
namespace PM.DataService
{
[ServiceContract]
public class PMService
{
[OperationContract]
public ObservableCollection<Job> GetAllJobs()
{
using (var context = new logisticDBEntities())
{
var result = context.Jobs.ToList();
result.ForEach(e => context.Detach(e));
return new ObservableCollection<Job>(result);
}
}
[OperationContract]
public ObservableCollection<Status> GetStatuses()
{
using (var context = new logisticDBEntities())
{
var result = context.Statuses.ToList();
result.ForEach(e => context.Detach(e));
return new ObservableCollection<Status>(result);
}
}
}
}
JobsViewModel
namespace PM.UI.ViewModel
{
public class JobsViewModel:INotifyPropertyChanged
{
private PMServiceClient serviceClient = new PMServiceClient();
public JobsViewModel()
{
this.RefreshAllJobs();
}
private void RefreshAllJobs()
{
this.serviceClient.GetAllJobsCompleted += (s, e) =>
{
this.AllJobs = e.Result;
};
this.serviceClient.GetAllJobsAsync();
}
private ObservableCollection<Job> allJobs;
public ObservableCollection<Job> AllJobs
{
get{
return this.allJobs;
}
set
{
this.allJobs = value;
OnPropertyChanged("AllJobs");
}
}
private ObservableCollection<Status> statuses;
public ObservableCollection<Status> Statuses
{
get
{
return this.statuses;
}
set
{
this.statuses = value;
this.OnPropertyChanged("Statuses");
}
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
I included my viewmodel in the MainWindow.xaml
MainWindow.xaml
<Window x:Class="PM.FullClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PM.UI"
xmlns:vms="clr-namespace:PM.UI.ViewModel"
Title="MainWindow" Height="475" Width="575">
<Window.DataContext>
<vms:JobsViewModel/>
</Window.DataContext>
Using a DataGrid i’ve successfully displayed all the jobs.
<DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding Path=AllJobs}" Margin="6">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=jobNo}" Header="Job #" />
<DataGridTextColumn Binding="{Binding Path=jobStatus}" Header="Status" />
<DataGridTextColumn Binding="{Binding Path=jobDate}" Header="Date" />
<DataGridTextColumn Binding="{Binding Path=Statuses}" Header="Status" />
</DataGrid.Columns>
</DataGrid>
JobsDataGrid_output

In the JobsDataGrid as you can see i’ve IDs of the Statuses.
Now the Statuses and Jobs have a one to many relationship where; a Job will hold the primary key of a Status.
What i want to do is show the respective statusCaption insted of an the jobStatus(statusId).
Edited as Ucodia adviced
I Inserted the code below
...
var result = context.Jobs.ToList();
result.ForEach(e => context.LoadProperty(e, "Status"));
result.ForEach(e => context.Detach(e));
...
and the result is still the same (the Status coloumn is still blank
I run the app in debug mode and got the following… hoping it’ll help someone explain me what I’m doing wrong.
>>>Screenshot of debug data

You are binding
Jobobjects to your DataGrid and in the columns you bind thejobStatusmember which is the status ID that your object model uses to navigate to the concreteStatusobject to which thestatusCaptionmember belong.So you just need to change your second column binding to use the
Statusnavigation property of theJobobject.Later I realised that you were detaching your job objects from their context on load. By default, navigation properties like Status on the Job model will be lazy loaded, which means they will be loaded only when requested. But for the model to be lazy loaded, it needs to be attached. Therefore, when loading your Job objects you also need to explicitely ask for the Status property to be loaded before detaching the entity.