【发布时间】:2018-06-29 04:16:29
【问题描述】:
我正在创建一个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
}
错误是
cannot convert from 'System.Collections.IEnumerable' to 'System.Collections.Generic.IEnumerable<System.Collections.IEnumerable>'
我怎样才能摆脱这个错误?
任何帮助将不胜感激。
【问题讨论】:
-
你能用 AddRange() 代替 Concat() 吗?
-
将 result、prodDetails 和 mainDetails 从声明为 IEnumerable 更改为声明为 IEnumerable
-
prodDetails = "";此行无法编译。你发布了你的实际代码吗? -
@MrFaisal 请将您问题中的所有代码替换为可编译的实际代码 - 因为您发布的代码由于大量输入错误而根本无法编译。
-
用该匿名类的具体实现重写它。
标签: c# linq asp.net-web-api2 ienumerable