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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:27:33+00:00 2026-05-19T16:27:33+00:00

Consider the following linq query: from r in result join oUS in onOrderUS on

  • 0

Consider the following linq query:

from r in result
join oUS in onOrderUS on r.ItemGUID equals oUS.ItemGUID into jOnOrderUS
from oUS in jOnOrderUS.DefaultIfEmpty()
let OnOrderUS = oUS != null ? oUS.UnitQty : 0
select (new Func<ItemMinMaxView>(() =>
{
   r.OnOrderUS = OnOrderUS;

   return r;
})).Invoke()

I want to select r from result, but fill a field with the data from oUS. Is there a better way to do this?

  • 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-19T16:27:34+00:00Added an answer on May 19, 2026 at 4:27 pm

    I too would like to see the query split into more logical parts to aid readability. But I would then take advantage of the Reactive Extensions (Rx) to cause the side effect you want (ie the value assignment).

    First up I would just create the query like Anthony suggested, but I want to check that your query is correct.

    If there are more than one onOrderUS records returned then you’ll only assign the last one found to the ItemMinMaxView record.

    If there will only ever be zero or one record then your query is fine, but it could be simpler.

    Either way, try this query instead:

    var query =
        from r in result
        join oUS in onOrderUS on r.ItemGUID equals oUS.ItemGUID into goUSs
        let OnOrderUS = goUSs.Sum(x => x.UnitQty)
        select new
        {
            Result = r,
            OnOrderUS
        };
    

    Then I’d get the final results (with the assignment side effect) like this:

    var output = query
        .Do(x => x.Result.OnOrderUS = x.OnOrderUS)
        .Select(x => x.Result)
        .ToArray();
    

    The .Do(...) method is part of Rx and is explicitly there for these kinds of side effects.

    You do get a load of good extension methods for IEnumerable<T> in Rx so if you haven’t checked it out you should. It’s even recently been promoted to a supported Microsoft developer tool.

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

Sidebar

Related Questions

Consider following LINQ-to-NHibernate queries: var q1 = from se in query.ToList<SomeEntity>() where prop1 ==
Consider the following SQL query: SELECT * FROM Orders WHERE (AdjShipDate IS NOT NULL
Lets consider the following linq statement. var ctx = new MoviesContext(); var movies =
Please consider the following snippet from an implementation of the Interpreter pattern: public override
Consider the following very basic C# code. using System; using System.Collections.Generic; using System.Linq; using
I am trying to do the following Linq query on a Visio Masters collection:
I am using DBContext API from EF 4.1. Consider following entity model (A, B,
consider following codes and classes: using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Serialization; namespace
Consider the following C# code: using System.Xml.Linq; namespace TestXmlParse { class Program { static
Consider the following code var q = from e in myCollection.AsQueryable<Entity>() where e.Name ==

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.