I am populating a class using Linq to SQL.
What I am trying to do is query my database, return two integer values and subtract the two values from each other, producing the result, but I can’t think of a smart way to do it.
What can I do in this case ?
If it is not clear, , then this psuedocode implementation should clarify what functionality I wish for :
DECLARE @currentVal INT, @previousVal INT
@currentVal = SELECT VALUE
FROM Table1
WHERE Date = CURRDATE()
@previousVal = SELECT VALUE
FROM Table1
WHERE Date = MIN(Date)
RETURN @currentVal - @previousVal
But in Linq to SQL, (from o in context.Table1 where Date = currentDate select Value), how can I subtract the other value from this? Is this possible?
I’d stick to having it as a broken out set of queries, because you can then test if the values were actually returned or not and handle the case where too many values are returned:
Putting it all into a giant linq statement makes too many assumptions (or at least, my implementation does).