[英]Problems with AnonymousType ASP.NET MVC
我收到一个错误,我不知道如何解决,这是我的代码:
var respaldos = db.Respaldoes.Where(x => x.type == "Backup");
if (con_filtro_fecha)
respaldos = respaldos.Where(x => x.start_time >= _desde && x.start_time <= _hasta);
if (con_agrupacion)
{
switch (agrupar)
{
case "dia":
respaldos = respaldos.GroupBy(x => new{
x.start_time.Year,
x.start_time.Month,
x.start_time.Day
})
.Select(x => new{
anio = x.Key.Year,
mes = x.Key.Month,
dia = x.Key.Day,
bytes = x.Sum(y => y.bytes_processed)
}).AsEnumerable();
break;
case "mes":
respaldos = respaldos.GroupBy(x => new{
x.start_time.Year,
x.start_time.Month
})
.Select(x => new{
anio = x.Key.Year,
mes = x.Key.Month,
bytes = x.Sum(y => y.bytes_processed)
}).AsEnumerable();
break;
}
}
如何修复“ AsEnumerable()”中出现的错误? 或者如果这不可能,我该怎么办?
错误:
没有任何默认的System.Collections.Generic.IEnumerable AnonymousType#1转换为System.Linq.IQueryable RespaldoServidores.Models.Respaldo。 对话中的存在(compruebe si le falta unaconversión)
当您调用AsEnumerable
您有2个问题。
首先, respaldos
最初是IQueryable<T>
,因此您不能为其分配Enumerable<T>
。
其次,元素类型不同。 我不确定respaldos
包含哪种类型的元素,但它与查询中的匿名类型不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.