[英]Retrieving Data From Multiple Tables in a LINQ to SQL query
我是 LINQ 的新手,我不確定如何從我的 SQL 服務器數據庫中的多個表中檢索數據,這是查詢:
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()
數據庫使用變量連接
我怎樣才能做到這一點?
你的 sql 查詢在 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
};
Linq 與 sql 非常相似,只是有點倒退。
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 }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.