2 つの集計列を返す FetchXML クエリがあります。
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='blocktrade'>
<attribute name='sourceref' alias='trade_count' aggregate='count'/>
<attribute name='allocationtradecount' alias='alloc' aggregate='sum'/>
<attribute name='organisation' alias='org' groupby='true'/>
</entity>
</fetch>
クエリを制限して、allocationtradecount に値を持つオブジェクトを返すようにすると、期待どおりに動作します。ただし、allocationtradecount が null のオブジェクトがある場合、その列は結果に返されません。
すなわち
(int)((AliasedValue)e["alloc_count"]).Value;
失敗します。これは「予想」ですか?null 値を合計するときに 0 が使用されるようにするにはどうすればよいですか?