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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:06:03+00:00 2026-05-12T15:06:03+00:00

The Scenario Currently I have a C# Silverlight Application That uses the domainservice class

  • 0

The Scenario

Currently I have a C# Silverlight Application That uses the domainservice class and the ADO.Net Entity Framework to communicate with my database. I want to load a child window upon clicking a button with some data that I retrieve from a server-side query to the database.

The Process

The first part of this process involves two load operations to load separate data from 2 tables. The next part of the process involves combining those lists of data to display in a listbox.

The Problem

The problem with this is that the first two asynchronous load operations haven’t returned the data by the time the section of code to combine these lists of data is reached, thus result in a null value exception…..

Initial Load Operations To Get The Data:

public void LoadAudits(Guid jobID)
        {
            var context = new InmZenDomainContext();

            var imageLoadOperation = context.Load(context.GetImageByIDQuery(jobID));
            imageLoadOperation.Completed += (sender3, e3) =>
            {
                imageList = ((LoadOperation<InmZen.Web.Image>)sender3).Entities.ToList();
            };

            var auditLoadOperation = context.Load(context.GetAuditByJobIDQuery(jobID));
            auditLoadOperation.Completed += (sender2, e2) =>
            {
                auditList = ((LoadOperation<Audit>)sender2).Entities.ToList();
            };
        }

I Then Want To Execute This Immediately:

IEnumerable<JobImageAudit> jobImageAuditList
                = from a in auditList
                  join ai in imageList
                  on a.ImageID equals ai.ImageID
                  select new JobImageAudit
                  {
                      JobID = a.JobID,
                      ImageID = a.ImageID.Value,
                      CreatedBy = a.CreatedBy,
                      CreatedDate = a.CreatedDate,
                      Comment = a.Comment,
                      LowResUrl = ai.LowResUrl,

                  };

            auditTrailList.ItemsSource = jobImageAuditList;

However I can’t because the async calls haven’t returned with the data yet…

Thus I have to do this (Perform the Load Operations, Then Press A Button On The Child Window To Execute The List Concatenation and binding):

private void LoadAuditsButton_Click(object sender, RoutedEventArgs e)
        {

            IEnumerable<JobImageAudit> jobImageAuditList
                = from a in auditList
                  join ai in imageList
                  on a.ImageID equals ai.ImageID
                  select new JobImageAudit
                  {
                      JobID = a.JobID,
                      ImageID = a.ImageID.Value,
                      CreatedBy = a.CreatedBy,
                      CreatedDate = a.CreatedDate,
                      Comment = a.Comment,
                      LowResUrl = ai.LowResUrl,

                  };

            auditTrailList.ItemsSource = jobImageAuditList;
        }

Potential Ideas for Solutions:

Delay the child window displaying somehow?
Potentially use DomainDataSource and the Activity Load control?!

Any thoughts, help, solutions, samples comments etc. greatly appreciated.

  • 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-12T15:06:04+00:00Added an answer on May 12, 2026 at 3:06 pm

    First of there is no point in delaying the display of a window. Instead you should design your code to be able to handle asynchronous updates to the data. In this case you have a somewhat interesting situation where you are performing two asynchronous load operations and you are only able to create the data for display when both operations have completed.

    One solution to this problem is to move the query where you combine the data to the server side. Then instead of retrieving Image and Audit objects from the server in two separate operations you can retrieve JobImageAudit objects.

    Another solution is to create something similar to a view-model for the data you retrieve. Here is a rough sketch to get you started:

    public class JobImageAuditViewModel : INotifyPropertyChanged {
    
      IEnumerable<Image> images;
    
      IEnumerable<Audit> audits;
    
      IEnumerable<JobImageAudit> jobImageAudits;
    
      public void GetData() {
         this.images = null;
         this.audits = null;
         this.jobImageAudits = null;
         OnPropertyChanged("JobImageAuditList");
         // Load images by using GetImageByIDQuery()
         // Load audits by using GetAuditByJobIDQuery()
      }
    
      void LoadImageCompleted(Object sender, EventArgs e) {
        // Store result of query.
        this.images = ...
        UpdateJobImageAuditList();
      }
    
      void LoadAuditCompleted(Object sender, EventArgs e) {
        // Store result of query.
        this.audits = ...
        UpdateJobImageAudits();
      }
    
      void UpdateJobImageAudits() {
        if (this.images != null && this.jobs != null) {
          // Combine images and audits.
          this.jobImageAudits = ...
          OnPropertyChanged("JobImageAudits");
        }
      }
    
      public IEnumerable<JobImageAudit> JobImageAudits {
        get {
          return this.jobImageAudits; 
        }
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    
      protected virtual void OnPropertyChanged(String propertyName) {
        var handler = PropertyChanged;
        if (handler != null)
          handler(this, new PropertyChangedEventArgs(propertyName));
      }
    
    }
    

    You then have to databind auditTrailList.ItemsSource to JobImageAuditViewModel.JobImageAudits. You can do this by setting the DataContext of the ChildWindow or UserControl that contains auditTrailList to an instance of JobImageAuditViewModel and add this attribute to the auditTrailList XAML:

    ItemsSource="{Binding JobImageAudits}"
    

    Actually the .NET RIA framework is designed to let the client-side generated entitiy classes assume the role of the view-model in an MVVM application. They can be extended on the client side and they support INotifyPropertyChanged. However, in your case you are using an entity on the client side that doesn’t exist on the server side. Combining my first suggestion with data-binding is probably the ultimate solution to your problem.

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

Sidebar

Related Questions

The Scenario Currently I have a c# silverlight business application. The application is hosted
Background Currently I have a C# Silverlight business application which uses RIA Services. The
Here is my scenario: I have a document, currently a FlowDocument, that I would
I currently have created a pagination JavaScript class that will automatically paginate comments when
Here's my scenario: I am using Silverlight, RIA and POCO objects (no Entity Framework;
We have a scenario where some .NET code is attempting to access the current
I have the following scenario in Silverlight 4: I have a notifications service Snippet
I have a WP7 app (Silverlight) that has a page with a textbox that
I have this existing environment: 1) ASP.NET 3.5 web application 2) forms authentication with
I have a scenario and I really need your help. I have a Silverlight

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.