Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since (comments) you mention that you're open to the option of changing the return type, I would declare something like:</p> <pre><code>public class TradeRisk { public int Id {get;set;} public string TCN {get;set;} // expand name to be meaningful public string Currency {get;set;} public decimal UsdValue {get;set;} } </code></pre> <p>and change the method to return <code>List&lt;TradeRisk&gt;</code>. We can apply the same <code>DataColumn</code> tricks as in my previous answer, but change the result - noting that to keep the results the same we need to preserve the <code>Distinct</code> etc.</p> <pre><code>var tradeId = tradeTableToFilter.Columns["TradeID"]; var currency = tradeTableToFilter.Columns["CURRENCY"]; var calculatedRisk = (from DataRow tradeRow in tradeTableToFilter.Rows let tradeIdVal = tradeRow[tradeId] where tradeIdVal != null select new { Id = 0, TCN = tradeIdVal.ToString(), Currency = tradeRow[currency], UsdValue = calculator.Invoke(tradeRow) }).Distinct(); return (from row in calculatedRisk select new TradeRisk { Id = row.Id, TCN = row.TCN, Currency = row.Currency, UsdValue = row.UsdValue }).ToList(); </code></pre> <p>This avoid all the <code>DataTable</code> overheads. If we <em>really</em> wanted, we could also implement <code>TradeRisk : IEquatable&lt;TradeRisk&gt;</code>, and then just do:</p> <pre><code>return ( from DataRow tradeRow in tradeTableToFilter.Rows let tradeIdVal = tradeRow[tradeId] where tradeIdVal != null select new TradeRisk { Id = 0, TCN = tradeIdVal.ToString(), Currency = tradeRow[currency], UsdValue = calculator.Invoke(tradeRow) }).Distinct().ToList(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload