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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:52+00:00 2026-05-26T10:40:52+00:00

I’m using WCF Dataservice / EF 4.1 and a WPF Client application. Here is

  • 0

I’m using WCF Dataservice / EF 4.1 and a WPF Client application.
Here is my problem in a simpler form. Lets say I query clients:

var query = (from o in ServiceRef.Clients.Expand("Addresses,PhoneNumbers,EmailAddresses")
                       where o.FirstName.ToLower().Contains(sf) ||
                             o.LastName.ToLower().Contains(sf) || ...
                         orderby o.LastName
                         select o).Take(100);

This is all I need to identity a client. However, down the road I mite want to see the Comments, purchase history or other related entities not “Expanded” in the first query. If I query again, using the same ServiceRef Context, I will never get “Comments” expanded.

I’m guessing this has to do with the Context finding the ‘Client’ entity is already tracked and therefor not executing the new query against the Service.

Now some posts say, one should never keep a DBContext around that long, which I don’t agree up on Completely. It’s a simple Master/Details scenario. Creating a new context for every ‘Details Query’ to get the additional data seems somehow wrong. Is there a way to force EF to “reload” an entity to get additional data?

I can, of course, expand every attached entity I ever need in the initial query. But then I xfer a massive amount of data for each search result. 95% of which will never ever be used.

To be clear. What I am asking for is more of a ‘best practice’ question. Is there a way in the middle? Between Expanding (…) all data all the time <> Creating new Context all the time.? Is there a way to load additional data if needed.

Thanx, Andreas

  • 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-26T10:40:53+00:00Added an answer on May 26, 2026 at 10:40 am

    Your question has two parts.

    How to get additional data?

    • You can either use ServiceRef.Clients.Expand("Comments") in your initial query but it is obviously something you don’t want – this is called eager loading
    • Or you can use ServiceRef.LoadProperty(client, "Comments") to populate comments just for single client – this can be called explicit loading

    How long should context be alive?

    It depends. Correct approach is indeed to keep the context alive as short as possible but it doesn’t mean to close context after each operation. Context should be used as unit of work and all related operations should be operated on the same context instance. In case of WPF / WinForm application it means that context can indeed live for a longer period of time – it is usually paired with some form / presenter / etc. You should not use same context among multiple forms which are not related and don’t form single unit of work / logical operation (objects in the same unit of work are operated and saved together).

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.