[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Linq -Getting the difference of two columns

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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