I'm trying to combine 2 lists from these:
var quartEst = Quarterly_estimates
.OrderByDescending (q => q.Yyyy)
.ThenByDescending (q => q.Quarter)
.Where (q =>
q.Ticker.Equals("IBM")
&&
q.Eps != null
)
.Select (q => new {
ticker = q.Ticker,
Quarter = q.Quarter,
Year = q.Yyyy,
Eps = q.Eps})
.AsEnumerable()
.Where (q => Convert.ToInt32(string.Format("{0}{1}", q.Year, q.Quarter)) > Convert.ToInt32(finInfo) );
var quartAct = Quarterlies
.OrderByDescending (q => q.Yyyy)
.ThenByDescending (q => q.Quarter)
.Where (q =>
q.Ticker.Equals("IBM")
&&
Convert.ToInt16(q.Yyyy) >= DateTime.Now.Year - 3
)
.Select (q => new {
Tick = q.Ticker,
Quarter = q.Quarter,
Year = q.Yyyy,
Eps = q.Eps_adj})
.AsEnumerable()
.Where (q => Convert.ToInt32(string.Format("{0}{1}", q.Year, q.Quarter)) <= Convert.ToInt32(finInfo));
I get the error for a simple Union command:
var quartComb = quartEst.Union(quartAct);
Here's the error:
Instance argument: cannot convert from 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Linq.IQueryable<AnonymousType#2>'
What do I need to do to achieve this merge?
To use the Union
method, the collections must have the same type. In order for two anonymous types to be considered the same, they must have exactly the same members with exactly the same types.
Try this:
var quartEst = Quarterly_estimates
...
.Select (q => new {
Tick = q.Ticker, // renamed ticker to Tick
Quarter = q.Quarter,
Year = q.Yyyy,
Eps = q.Eps})
...
var quartAct = Quarterlies
.Select (q => new {
Tick = q.Ticker,
Quarter = q.Quarter,
Year = q.Yyyy,
Eps = q.Eps_adj})
...
var quartComb = quartEst.Union(quartAct);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With