2

I'm new to LINQ and I'm not sure how to retrieve data from multiple tables from my SQL server database, here's the query:

SELECT cp.*, tsd.Action, tsd.CurrencyPair 
from TradeStatsData tsd, CalculatedPrices cp 
where tsd.TradeID = cp.TradeID and cp.Price is null and cp.ActiveTime < GETDATE()

The database uses the variable connection

How can I do this?

2 Answers 2

2

Your sql query would be something like this in LINQ:

var result = from tsd in TradeStatsData
             join cp in CalculatedPrices on tsd.TradeID equals cp.TradeID
             where cp.Price == null && cp.ActiveTime < DateTime.Now
             select new
             {
                CP = cp,
                Action = tsd.Action,
                CurrencyPair = tsd.CurrencyPair
             };
Sign up to request clarification or add additional context in comments.

Comments

0

Linq is very similar to sql, just a little backwards.

from tsd in TradeStatsData
join cp in CalculatedPrices on tsd.TradeID equals cp.TradeID
where cp.Price == null && cp.ActiveTime < DateTime.Now
select new { cp.Col1... cp.ColN, tsp.Action, tsp.CurrencyPair }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.