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 6893343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:38:49+00:00 2026-05-27T06:38:49+00:00

I am developing an application using WPF/MVVM. I have a WCF data service project

  • 0

I am developing an application using WPF/MVVM. I have a WCF data service project which provides operations for retrieving data from an ADO.NET data model using entity framework. I then have a wpf client which binds to viewmodel properties that fetch from the WCF service. The scenario involves clients/offices. The client entity has a navigation property of type office, as is implemented as a foreign key in the database. The problem is that when my viewmodel gets the list of clients from the data service, the navigation property is null. The service operation however does retrieve this information.

WCF Service Operation

[OperationContract]
public IEnumerable<Client> GetClientsByOffice(int officeID)
{
    using (var context = new LDC_Entities())
    {
        var result = context.Clients.Include("Registered_Office")
            .Where(c => c.Registered_Office_ID == officeID).ToList();

        result.ForEach(c => context.Detach(c));
        return result;
    }
}

As you can see the office property is loaded within the context query. If I put a breakpoint in at this point, the result variable holds the clients information, and the navigation property is also filled as expected.

WPF ViewModel

private void RefreshClients()
{
    serviceClient.GetClientsByOfficeCompleted += (s, e) =>
    {
            Clients = e.Result;
            foreach (Client c in Clients)
                MessageBox.Show(c.Office.City);
    };

    this.serviceClient.GetClientsByOfficeAsync(CurrentOffice.Office_ID);
}

If I inspect the Clients property after this method is called, the navigation property is now empty, and as such the message box call I put in throws a null pointer exception. It appears that as it comes through the WCF service, it drops the navigation properties of the client objects.

Please could anyone explain how this information can be retained when making this call?

Many thanks in advance,
Mike

  • 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-05-27T06:38:49+00:00Added an answer on May 27, 2026 at 6:38 am

    As you can see the office property is loaded within the context query. If I put a breakpoint in at this point, the result variable holds the clients information, and the navigation property is also filled as expected.

    I’m not sure which point you’re talking about, as there are multiple lines of code there. But the object graph gets shredded when you detach entities.

    The solution presented in that question is to use a NoTracking query so you don’t have to detach:

    using (var context = new LDC_Entities())
    {
        context.Job.MergeOption = MergeOption.NoTracking;
        return context.Clients.Include("Registered_Office")
            .Where(c => c.Registered_Office_ID == officeID)
            .ToList();
    }
    

    This solution will probably work better for you than it did in that question because they also needed to do an update, which requires object tracking, whereas you’re just doing a query.

    Another way to solve this is to avoid exposing the classes from your data persistence layer to higher level layers. Then you don’t have to worry about things like how entities serialize, as you only work with them when working directly with the data persistence layer. This also gives other advantages, like looser coupling between layers, and exposing less unnecessary data to higher level layers. Using a library like AutoMapper can help reduce some of the boilerplate of copying data between layers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which I am developing using WPF\Prism\MVVM. All is going well
I am developing an application in WPF using the MVVM pattern. If I have
I'm developing a WPF application using MVVM. Inside a Window, I have a control
I am developing a WPF application (using MVVM) and have implemented IDataErrorInfo on my
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I'm developing a WPF application using the MVVM pattern and I need to display
Hello I'm developing a WPF Desktop application using MVVM and I'll like for my
I am currently developing an application in C# using WPF, I have always only
I am developing a WPF application using the MVVM pattern as described by Josh
I have recently joined a new developing project building a thick client application using

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.