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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:12:05+00:00 2026-05-17T02:12:05+00:00

I have a linq statement which calls a stored proc and returns a list

  • 0

I have a linq statement which calls a stored proc and returns a list of items and descriptions.

Like so;

var q = from i in doh.usp_Report_PLC()
where i.QTYGood == 0
orderby i.PartNumber
select new Parts() { PartNumber = i.PartNumber, Description = i.Descritpion.TrimEnd() };

I then have another SQL statement which returns the quantities on order and delivery date for each of those items. The Parts class has two other properties to store these. How do I update the existing Parts list with the other two values so that there is one Parts list with all four values?

UPDATE

The following code now brings out results.

                var a = from a1 in db.usp_Optos_DaysOnHand_Report_PLC()
                    where a1.QTYGood == 0
                    orderby a1.PartNumber
                    select new Parts() { PartNumber = a1.PartNumber, Description = a1.Descritpion.TrimEnd() };

            var b = from b1 in db.POP10110s
                    join b2 in db.IV00101s on b1.ITEMNMBR equals b2.ITEMNMBR
                    //from b3 in j1.DefaultIfEmpty()
                    where b1.POLNESTA == 2 && b1.QTYCANCE == 0
                    group b1 by new { itemNumber = b2.ITMGEDSC } into g
                    select new Parts() { PartNumber = g.Key.itemNumber.TrimEnd(), QtyOnOrder = g.Sum(x => Convert.ToInt32(x.QTYORDER)), DeliveryDue = g.Max(x => x.REQDATE).ToShortDateString() };

            var joinedList = a.Join(b,
                    usp => usp.PartNumber,
                    oss => oss.PartNumber,
                    (usp, oss) =>
                         new Parts
                         {
                             PartNumber = usp.PartNumber,
                             Description = usp.Description,
                             QtyOnOrder = oss.QtyOnOrder,
                             DeliveryDue = oss.DeliveryDue
                         });

            return joinedList.ToList();
  • 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-17T02:12:06+00:00Added an answer on May 17, 2026 at 2:12 am

    Assuming your “other SQL statement” returns PartNumber, Quantity and DeliveryDate, you can join the lists into one:

    var joinedList = q.Join(OtherSQLStatement(), 
                            usp => usp.PartNumber,
                            oss => oss.PartNumber,
                            (usp, oss) => 
                                 new Parts
                                        {
                                            PartNumber = usp.PartNumber,
                                            Description = usp.Description,
                                            Quantity = oss.Quantity,
                                            DeliveryDate = oss.DeliveryDate
                                        }).ToList();
    

    You can actually combine the queries and do this in one join and projection:

    var joinedList = doh.usp_Report_PLC().
                         Where(i => i.QTYGood == 0).
                         OrderBy(i => i.PartNumber).
                         Join(OtherSQLStatement(), 
                              i => i.PartNumber,
                              o => o.PartNumber,
                              (i, o) => 
                                   new Parts
                                        {
                                            PartNumber = i.PartNumber,
                                            Description = i.Description,
                                            Quantity = o.Quantity,
                                            DeliveryDate = o.DeliveryDate
                                        }).ToList();
    

    And again: I assume you have PartNumber in both returned collections to identify which item belongs to which.

    Edit

    In this case the LINQ Query syntax would probably be more readable:

    var joinedList = from aElem in a
                     join bElem in b
                     on aElem.PartNumber equals bElem.PartNumber into joinedAB
                     from abElem in joinedAB.DefaultIfEmpty()
                     select new Part
                                {
                                    PartNumber = aElem.PartNumber,
                                    Description = aElem.Description,
                                    DeliveryDue = abElem == null ? null : abElem.DeliveryDue,
                                    QtyOnOrder = abElem == null ? null : abElem.QtyOnOrder
                                };
    

    Your DeliveryDue and QtyOnOrder are probably nullable. If not, replace the nulls by your default values. E.g. if you don’t have the element in b and want QtyOnOrder to be 0 in the resulting list, change the line to

    QtyOnOrder = abElem == null ? 0 : abElem.QtyOnOrder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using multiple joins in a statement and Have tried to make linq-to-SQl
I'm trying to filter a list of objects using linq. When i filter by
I have replicated a stripped-down version of my code that has recently been re-written
I have a simple view defined MSSQL 2008. The view is defined as follows:
I've discovered a very nasty gotcha with Linq-to-sql, and i'm not sure what the
I am attempting to add Entity Framework, code first, to an MVC application that's
...I'm a little confused, or unsure about how to deal with errors that arise
I'm writing a tool, and the first part of that tool is to collect
I've used Linq2SQL lots and am familiar with most of the concepts (up to

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.