Solved

Linq -Getting the difference of two columns

Posted on 2014-02-10
1
317 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
1 Comment
 
LVL 11

Accepted Solution

by:
jasonduan earned 500 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now