Unable to concatenate two IEnumerable lists [duplicate]
Unable to concatenate two IEnumerable lists [duplicate]
This question already has an answer here:
I am creating a WEB API
. I have two IEnumerable
lists. And at the end I want to concatenate them.
WEB API
IEnumerable
IEnumerable result;
IEnumerable prodDetails = new List<tj_xhqd>();
IEnumerable mainDetails= new List<tj_xhqd>();
int prodInterval, prodCount = 0;
int mainInterval, mainCount = 0;
prodCount = giveProdCount(msn, dt);
if(prodCount==0)
{
prodDetails = "";
}
else if (prodCount<=500)
{
prodDetails = mdcEntitites.tj_xhqd
.Where( m => (m.zdjh == msn) && (m.sjsj >= dt) )
.Select( x => new { MSN = x.zdjh, PingDateTime = x.sjsj, PingValue = x.xhqd } )
.ToList();
}
else
{
prodInterval = prodCount / 500;
prodDetails = mdcEntitites.tj_xhqd
.AsNoTracking()
.Where( m => (m.zdjh == msn) && (m.sjsj >= dt) )
.AsEnumerable()
.Select( (x, i) => new { MSN = x.zdjh, PingDateTime = x.sjsj, PingValue = x.xhqd, i = i } )
.Where( x => x.i % prodInterval == 0 )
.ToList();
}
mainCount = giveMainCount(msn, dt);
if(mainCount==0)
{
mainDetails = "";
}
else if (mainCount <=500)
{
mainDetails = kesc.tj_xhqd
.Where(m => (m.zdjh == msn) && (m.sjsj >= dt))
.Select(x => new { MSN = x.zdjh, PingDateTime = x.sjsj, PingValue = x.xhqd })
.ToList();
}
else
{
mainInterval = mainCount / 500;
mainDetails = kesc.tj_xhqd
.AsNoTracking()
.Where(m => (m.zdjh == msn) && (m.sjsj >= dt))
.AsEnumerable()
.Select((x, i) => new { MSN = x.zdjh, PingDateTime = x.sjsj, PingValue = x.xhqd, i = i })
.Where(x => x.i % mainInterval == 0)
.ToList();
}
if(prodDetails.ToString() == "")
{
result = mainDetails;
}
else if(mainDetails.ToString()=="")
{
result = prodDetails;
}
else
{
result = prodDetails.Concat( mainDetails ); // here I am getting error
}
The error is
cannot convert from 'System.Collections.IEnumerable' to 'System.Collections.Generic.IEnumerable<System.Collections.IEnumerable>'
How can I get rid of this error?
Any help would be highly appreciated.
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Change result, prodDetails, and mainDetails from being declared as IEnumerable to being declared as IEnumerable<tj_xhqd>
– MineR
Jun 29 at 4:20
prodDetails = "";
this line won't compile. Have you posted your actual code?– Dai
Jun 29 at 4:24
prodDetails = "";
@MrFaisal Please replace all of the code in your question with the actual code that compiles - because the code you've posted does not compile at all due to numerous typing errors.
– Dai
Jun 29 at 4:26
Rewrite it with a concrete implementation of that anonymous class.
– MineR
Jun 29 at 5:05
1 Answer
1
Here's the sample program to combine IEnumerable list A and B in to C..
Hope this helps.
IEnumerable<int> A = new List<int>() { 1, 2, 3 };
IEnumerable<int> B = new List<int>() { 4, 5, 7 };
IEnumerable<int> C = A.Union(B);
Concat isn't the problem, please read the question well.
– Gert Arnold
2 days ago
Could you use AddRange() instead of Concat()?
– PepitoSh
Jun 29 at 4:18