Solved

Linq -Getting the difference of two columns

Posted on 2014-02-10
1
333 Views
Last Modified: 2016-02-10
New to Linq. I am trying to do the following:

1. Select two fields. Each field exists in a different table
2. get the difference between those two fields.

How to do? Query is below. Any help would be greatly appreciated.

Jason

        private HeSubroReceived GetNetUnitValue(int currentClaim, int unitId)
        {
            decimal salvage=0.00;
            salvage = (from a in _subContext.Salvage where a.claim==currentClaim && 
            a.UnitId==unitId select SaleAmount);

            decimal unitValue=0.00;
 
            unitValue = (from b in _subContext.HeUnits where a.claim==currentClaim && a.UnitId==unitId select UnitValues);

            var NetUnitValue = new HeSubroReceived

            NetUnitValue=unitValue-salvage;
           
             return NetUnitValue;
               

        }
0
Comment
Question by:jazzcatone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
jasonduan earned 500 total points
ID: 39847866
Your question is not very clear. However, is this what you are looking for?

var query = from a in _subContext.Salvage 
            join b in _subContext.HeUnits on new {UnitId = a.UnitId, Claim = a.claim} 
                                       equals new {UnitId = b.UnitId, Claim = b.claim} 
	    where a.UnitId == unitId && a.claim == currentClaim
	    select b.UnitValues - a.SaleAmount;
return query.FirstOrDefault();

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question