parentIdsでレコードを取得したい。しかし、このLinq式は、parentId値が0の要素を提供してくれました。
var orders =
OrderEquityTransactions.AsParallel().Where(
o => o.FinancialInstrumentId == financialInstrumentPrice.FinancialInstrumentId &&
o.ParentId != 0 &&
o.DebitCredit == "A" ? o.Price >= financialInstrumentPrice.Price : o.Price <= financialInstrumentPrice.Price).ToList();
少し掘り下げた後、2つの角かっこを追加して式を書き直し、問題を解決しました。
var orders =
OrderEquityTransactions.AsParallel().Where(
o => o.FinancialInstrumentId == financialInstrumentPrice.FinancialInstrumentId &&
o.ParentId != 0 &&
(o.DebitCredit == "A" ? o.Price >= financialInstrumentPrice.Price : o.Price <= financialInstrumentPrice.Price)).ToList();
この動作の理由は何ですか?
最初のケースでは、次のように解釈されたためです。
o => (o.FinancialInstrumentId == financialInstrumentPrice.FinancialInstrumentId
&& o.ParentId != 0 && o.DebitCredit == "A")
? o.Price >= financialInstrumentPrice.Price
: o.Price <= financialInstrumentPrice.Price
これは絶対に別です。
演算子の優先順位に関するこの記事をお読みください。
三項条件演算子は、条件付きANDよりも優先度が低くなります。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加