Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:43:42+00:00 2026-06-16T19:43:42+00:00

Consider the following model… DataModel I’ve a WCF data Service (PMService) that exposes the

  • 0

Consider the following model…

DataModel

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

enter image description here

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
Debug info

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:43:44+00:00Added an answer on June 16, 2026 at 7:43 pm

    You are binding Job objects to your DataGrid and in the columns you bind the jobStatus member which is the status ID that your object model uses to navigate to the concrete Status object to which the statusCaption member belong.

    So you just need to change your second column binding to use the Status navigation property of the Job object.

    <DataGridTextColumn Binding="{Binding  Path=Status.statusCaption}" Header="Status" />
    

    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.

    using (var context = new logisticDBEntities())
    {
        var result = context.Jobs.ToList();
        result.ForEach(e => context.LoadProperty(e, "Status"));
        result.ForEach(e => context.Detach(e));
        return new ObservableCollection<Job>(result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following data model: Suppose I have a table called SuperAwesomeData where each
Consider the following method that stops a service: Public Function StopService(ByVal serviceName As String,
Consider the following property UserName of a Model Class. You can see that the
Consider the following scenario: You have an account model You have an external service
Consider the Following object model (->> indicates collection): Customer->Orders Orders->>OrderLineItems->Product{Price} The app is focused
Consider the following Django models: class Host(models.Model): # This is the hostname only name
Consider the following code: [Authenticate(Order = 1)] public ActionResult SomeActionThatRequiresAuthentication() { var model =
Consider the following Friendship model, where for every friendship made, there is a User
Consider the following declarative User model in SQLAlchemy: class User(Base): id = Column(Integer, primary_key=True)
The problem is best explained by example, consider the following two models: class Topping(models.Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.