无法串联两个IEnumerable列表

时间:2018-06-29 04:16:29

标签: c# linq asp.net-web-api2 ienumerable

我正在创建一个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>'

如何摆脱这个错误?

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

这是将IEnumerable列表A和B组合到C中的示例程序。 希望这会有所帮助。

df1