?
Solved

Linq -Getting the difference of two columns

Posted on 2014-02-10
1
Medium Priority
?
352 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 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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