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

  • Home
  • SEARCH
  • 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 7703783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:32:15+00:00 2026-05-31T23:32:15+00:00

I have a Silverlight delegate which gets an ObservableCollection in the EventArgs Result. The

  • 0

I have a Silverlight delegate which gets an ObservableCollection in the EventArgs Result. The DTO myType has fields Order, StartDate, Status, PlannedAmount, ActualAmount, and few others. The query on the WCF service side gets several rows per Order, varying only by PlannedAmount and ActualAmount.

Order # | StartDate | PlannedAmount| ActualAmount | Order Comments ....
Order A | March 15  |    20.00     |     0.00     | Comment 1 ...
Order A | March 15  |    30.00     |     0.00     | Comment 1 ...
Order A | March 15  |    10.00     |     0.00     | Comment 1 ...
Order A | March 15  |     0.00     |    30.00     | Comment 1 ...
Order B | March 25  |    10.00     |      0       | Comment 2 ...
Order B | March 25  |     0.00     |     5.00     | Comment 2 ...

I would like to show only one row per Order and sum all the PlannedAmount and ActualAmount values. I prefer to change this in the presentation layer as I don’t know what other consumers of the WCF Operation require. So I want to roll it up to…

Order # | StartDate | PlannedAmount| ActualAmount | Order Comments ....
Order A | March 15  |    60.00     |    30.00     | Comment 1 ...
Order B | March 25  |    10.00     |    5.00      | Comment 2 ...

And then make this an ObservableCollection of the same type that I had before.

I have tried this but I cannot seem to get anything but the Key and the Sum values.

    var Orders =
        from wo in OrdersPerOperation
        group wo by wo.OrderNo
        into g
        select new
        {
            OrderNo = g.Key,
            Planned = g.Sum(wo => wo.Planned),
            Actual = g.Sum(wo => wo.Actual),
            OrderComments = g.Select(wo => wo.Equipment),
            StartDate = g.Select(wo => wo.StartDate),
            Status = g.Select(wo => wo.Status),
            OrderType = g.Select(wo => wo.OrderType) //,...
        };

Edit
Getting just the key and two sums is straight-forward:

var Orders =
        from wo in OrdersPerOperation
        group wo by wo.OrderNo
        into g
        select new
        {
            OrderNo = g.Key,
            Planned = g.Sum(wo => wo.Planned),
            Actual = g.Sum(wo => wo.Actual)
        }

The challenge is getting all of the other fields, which are repetitive to also show in the result.

EDIT
I made this guess that this might work like a self-referencing SQL query. I believe I am on the right track with this, in that each element has data in the correct format. I still cannot set the results to the ItemsSource of the Silverlight grid, which I could bind, before all of this Linq confusion. The IDE warns me that FirstOrDefault is a possible NullReferenceException.

var workOrders = from wo in workOrdersPerOperation
                group wo by wo.OrderNo
                into g
                select new
                {
                    OrderNo = g.Key,
                    Planned = g.Sum(wo => wo.Planned),
                    Actual = g.Sum(wo => wo.Actual),
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).Location,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).Equipment,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).StartDate,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).Status,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).OrderType,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).AccType,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).WorkCenter,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).Description,
                    g.FirstOrDefault(wo => wo.OrderNo == g.Key).Priority
                };

Can anyone get me past this step? I still need to bind it to the control.

  • 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-31T23:32:16+00:00Added an answer on May 31, 2026 at 11:32 pm

    I’m pretty sure that this

    Location = g.FirstOrDefault(wo => wo.OrderNo == g.Key).Location,
    

    Will produce the same result as this

    Location = g.FirstOrDefault().Location,
    

    Additionally, you only need to use FirstOrDefault if your collection might be empty. However, the group would not exist if there were no items in it. This allows you to simplify it down to this.

    Location = g.First().Location,
    

    You can make the final solution

    var orders = from wo in ordersPerOperation
        group wo by wo.OrderNo
        into g
        select new MyType
        {
            OrderNo = g.Key,
            Planned = g.Sum(wo => wo.Planned),
            Actual = g.Sum(wo => wo.Actual),
            Location = g.First().Location,
            Equipment = g.First().Equipment,
            StartDate = g.First().StartDate,
            Status = g.First().Status,
            OrderType = g.First().OrderType,
            AccType = g.First().AccType,
            WorkCenter = g.First().WorkCenter,
            Description = g.First().Description,
            Priority = g.First().Priority
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Silverlight 4 I have a custom service class which has an asynchronous Completed
in my Silverlight 4 application, I have an ObservableCollection which consists of objects of
I have a Silverlight DataGrid that contains a single template column which displays a
I have silverlight 2.0 application and which uses WCF service to get data and
I have a Silverlight 4 application which talks to a 'manager' class, which talks
I have silverlight application in asp.net web. In web application i have folder which
I have a website which contains a small Silverlight plugin that calls a very
I have a custom multi-media player written in silverlight which displays both images and
I have Silverlight application which connects to a WCF service. If i open the
I have silverlight application which is having Current time and date , ia m

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.