C# code

Hello,

See below statement & comments:

foreach (var ttQH in (from QH in ttQuoteHed
join QD in Db.QuoteDtl on
new {QH.Company, QH.QuoteNum} equals
new {QD.Company, QD.QuoteNum}
select new{QH, QD.ExtCost_c})) - "Here I need select all records belong to Quote not only new one"

{
ttQH.QH["TotItemCost_c"] = ttQH.ExtCost_c;  - "Here I need show SUM of ExtCost"
}

Have no idea how to do that.

thanks

henry
henryk123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis ParaskevopoulosCommented:
Hi,

Do you need for every Quote the sum of all ExtCost in the Quote details?

May i suggest the following approach:

var quotes = ttQuoteHed
    .GroupJoin
    (
        Db.QuoteDtl,
        QH => new {QH.Company, QH.QuoteNum} ,
        QD => new {QD.Company, QD.QuoteNum} ,
        (h,d) => new {h, sumOfExtraCosts = d.Sum(c=>c.ExtCost_c)}
    )

Open in new window


After the execution of the above, you will have a "list" of objects with 2 properties. The first property will be of type of ttQuoteHed and will have all the columns of that table. The second property will be named sumOfExtraCosts and will have the sum of extra costs for that quote.

Giannis
henryk123Author Commented:
Maybe my explanation was not clear enough.
I have a quote with multiple parts on it.
ex: Quote # 1
Part x
Part y
Part z
I will need take value from field "ExtCost_c" belong to each part number, SUM and display in quote header

thanks

henry
Ioannis ParaskevopoulosCommented:
Hi,

Sorry for the late reply. I am still not 100% sure the exact form you would like to show. Is it possible to give an example of the desired results?

My example is summing all the ExtCost_c col in the details of each quote and has it along with each header. So for instance if you would run the following:

var quotes = ttQuoteHed
    .GroupJoin
    (
        Db.QuoteDtl,
        QH => new {QH.Company, QH.QuoteNum} ,
        QD => new {QD.Company, QD.QuoteNum} ,
        (h,d) => new {h, sumOfExtraCosts = d.Sum(c=>c.ExtCost_c)}
    )
foreach(var q in quotes)
{
    Console.WriteLine(String.Format("Company: {0}, QuoteNo: {1}, SumOfExtraCosts: {2}",q.h.Company,q.h.QuoteNum,q.sumOfExtraCosts ));
}

Open in new window


In other words the above query will result in one object for each quote header. That resulting object will have two properties. One property (h) will contain the whole header row, so h.QuoteNum has the QuoteNum value for that quote etc.
The other property (sumOfExtraCosts ) has the sum of all the ExtCost_c column of the details of that specific quote header.

If that is not very clear, please give a sample of your data. I would need 2 or 3 rows in ttQuoteHed and as many as you like for each of them in QuoteDtl. I would also like to see what is the form of the results you expect to see after running your code. Given this info i will be more than happy to provide you with a sample code.

Giannis

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
henryk123Author Commented:
Working,

thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.