1
我有以下SQL查詢被轉換爲LINQ。我正在使用oracle數據庫。使用LINQ中where子句中的If語句
SELECT TableA.Id,
TableA.Date,
TableA.ItemId
TableB.Quantity,
TableB.Total
FROM TableA, TableB, TableC, TableD
Where TableA.Id = TableB.Id and
TableA.Id = TableC.Id (+) and
TableA.Id = TableD.Id (+) and
TableA.ItemId = _itemId and
TableA.Date >= _from_date and
TableA.Date < _to_date and
DECODE(TableD.Id,NULL,0,1) = (some boolean variable)
表A和表C具有一個< - >(一個或零),其中表C是可選的。
LINQ查詢我寫的是:
var data = from ta in context.TableAs
join tB in context.TableBs
on tA.Id equals tB.Id
join tD in context.TableDs
on tA.Id equals tD.Id into A
from itemA in A.DefaultIfEmpty()
join tC in context.TableCs
on itemA.tA.Id equals tC.Id into B
from itemB in B.DefaultIfEmpty()
where itemA.tA.ItemId == _itemId &&
itemA.tA.Date >= _startDate &&
itemA.Ta.Date< _endDate && // this is where I got stuck...
select new
{
itemA.tA.Id,
itemA.tA.Date,
itemA.tA.ItemId,
itemA.tB.Quantity,
itemA.tB.BalanceQuantity,
};
我怎麼能寫我的構建LINQ查詢的WHERE子句中的SQL QUERTY最後一行(即
DECODE(TableD.Id,NULL,0,1) = some boolean variable)
?
非常感謝...
你可以這樣寫:tD.Id ??真正。我假設你的數據庫中的ID是位型的 – 2013-03-19 06:31:45