Need to modify LINQ statement

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I am having issues. The order of the XML file Im reading may be out of order. Im trying to order it by _PrepaymentSpeedValue.
Heres the xml:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_ANALYSIS <span style="color:Red; _SeriesNumber<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3898<span style="color:Black; " <span style="color:Red; _CollateralStatus<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Assumed<span style="color:Black; " <span style="color:Red; _Source<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; FHLMC<span style="color:Black; " <span style="color:Red; _DealerName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; CITIGROUP GLOBAL MARKETS, INC.<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; OCS_GROUP <span style="color:Red; _Number<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 7<span style="color:Black; " <span style="color:Red; _SettlementDate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 2011-07-29<span style="color:Black; " <span style="color:Red; _FirstPaymentDate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 2011-08-15<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CLASS <span style="color:Red; _Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IM<span style="color:Black; " <span style="color:Red; _AssumedPrice<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3.5<span style="color:Black; " <span style="color:Red; _Cap<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 999<span style="color:Black; " <span style="color:Red; _InitialCouponRate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5.000000000<span style="color:Black; " <span style="color:Red; _InitialAccrualPeriod<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 28<span style="color:Black; " <span style="color:Red; _Floor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; _Multiplier<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; _OriginalUpb<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 22121076.000000<span style="color:Black; " <span style="color:Red; _Spread<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; SCENARIO <span style="color:Red; _PrepaymentSpeedValue<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 100<span style="color:Black; " <span style="color:Red; _PrepaymentSpeedType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; PSA<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_DETAIL <span style="color:Red; _YieldPct<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 90.16286<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CLASS <span style="color:Red; _Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IM<span style="color:Black; " <span style="color:Red; _AssumedPrice<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3.5<span style="color:Black; " <span style="color:Red; _Cap<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 999<span style="color:Black; " <span style="color:Red; _InitialCouponRate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5.000000000<span style="color:Black; " <span style="color:Red; _InitialAccrualPeriod<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 28<span style="color:Black; " <span style="color:Red; _Floor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; _Multiplier<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; _OriginalUpb<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 22121076.000000<span style="color:Black; " <span style="color:Red; _Spread<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; SCENARIO <span style="color:Red; _PrepaymentSpeedValue<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 250<span style="color:Black; " <span style="color:Red; _PrepaymentSpeedType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; PSA<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_DETAIL <span style="color:Red; _YieldPct<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 32.58377<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CLASS <span style="color:Red; _Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IM<span style="color:Black; " <span style="color:Red; _AssumedPrice<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3.5<span style="color:Black; " <span style="color:Red; _Cap<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 999<span style="color:Black; " <span style="color:Red; _InitialCouponRate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5.000000000<span style="color:Black; " <span style="color:Red; _InitialAccrualPeriod<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 28<span style="color:Black; " <span style="color:Red; _Floor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; _Multiplier<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; _OriginalUpb<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 22121076.000000<span style="color:Black; " <span style="color:Red; _Spread<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; SCENARIO <span style="color:Red; _PrepaymentSpeedValue<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 400<span style="color:Black; " <span style="color:Red; _PrepaymentSpeedType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; PSA<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_DETAIL <span style="color:Red; _YieldPct<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; -1.06240<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CLASS <span style="color:Red; _Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IM<span style="color:Black; " <span style="color:Red; _AssumedPrice<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3.5<span style="color:Black; " <span style="color:Red; _Cap<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 999<span style="color:Black; " <span style="color:Red; _InitialCouponRate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5.000000000<span style="color:Black; " <span style="color:Red; _InitialAccrualPeriod<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 28<span style="color:Black; " <span style="color:Red; _Floor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; _Multiplier<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; _OriginalUpb<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 22121076.000000<span style="color:Black; " <span style="color:Red; _Spread<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; SCENARIO <span style="color:Red; _PrepaymentSpeedValue<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 395<span style="color:Black; " <span style="color:Red; _PrepaymentSpeedType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; PSA<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_DETAIL <span style="color:Red; _YieldPct<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; -0.02524<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; CLASS <span style="color:Red; _Id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; IM<span style="color:Black; " <span style="color:Red; _AssumedPrice<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3.5<span style="color:Black; " <span style="color:Red; _Cap<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 999<span style="color:Black; " <span style="color:Red; _InitialCouponRate<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5.000000000<span style="color:Black; " <span style="color:Red; _InitialAccrualPeriod<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 28<span style="color:Black; " <span style="color:Red; _Floor<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; _Multiplier<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; " <span style="color:Red; _OriginalUpb<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 22121076.000000<span style="color:Black; " <span style="color:Red; _Spread<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; SCENARIO <span style="color:Red; _PrepaymentSpeedValue<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 500<span style="color:Black; " <span style="color:Red; _PrepaymentSpeedType<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; PSA<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; PRICE_YIELD_DETAIL <span style="color:Red; _YieldPct<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; -20.84795<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_UNIT<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; OCS_GROUP<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; PRICE_YIELD_ANALYSIS<span style="color:Blue; >

[/code]

and this is the code:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; for (<span style="color:Blue; var c = 0; c < uniqueColumns.Count; c++)
{
<span style="color:Blue; string header = <span style="color:Blue; string.Concat((uniqueColumns[c].Element(<span style="color:#A31515; "SCENARIO").Attribute(<span style="color:#A31515; "_PrepaymentSpeedValue").Value).OrderBy(i => uniqueColumns[c].Element(<span style="color:#A31515; "SCENARIO").Attribute(<span style="color:#A31515; "_PrepaymentSpeedValue").Value), <span style="color:#A31515; "%") + <span style="color:#A31515; "</TC><TC BREAKSTATUS="4 " + <span style="color:#A31515; " PSA";
<span style="color:Blue; string percentage = uniqueColumns[c].Element(<span style="color:#A31515; "PRICE_YIELD_DETAIL").Attribute(<span style="color:#A31515; "_YieldPct").Value;
...
}
[/code]

I added: <span style="white-space:pre .OrderBy(i => uniqueColumns[c].Element("SCENARIO").Attribute("_PrepaymentSpeedValue").Value)
<span style="white-space:pre This doesnt work. Please help!
<span style="white-space:pre TIA!

View the full article
 
Back
Top