Solved

Linq -Getting the difference of two columns

Posted on 2014-02-10
1
327 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
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

777 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