我有一个属性
public IEnumerable<producto> p_producto {
get {
return ((from ii in contexto.productos
orderby ii.nombre ascending
select new producto {
productoID = ii.productoId,
nombre = ii.nombre,
descripcion = ii.descripcion,
categoria = ii.categoria,
precio = ii.precio}));
}
}
在Default.aspx
中public IEnumerable<producto> filtroCategoria()
{
IEnumerable<producto> productos = repositorio.p_producto; <---- Error why ?
}
摘要
无法隐式转换类型 '
System.Collections.Generic.IEnumerable<TiendaDeportes.Modelos.producto>
' 到'System.Collections.Generic.IEnumerable<TiendaDeportes.producto>
'。 存在显式转换(您是否错过了演员?)
答案 0 :(得分:2)
您有两个名为producto
的班级。一个在TiendaDeportes
命名空间内,另一个在TiendaDeported.Modelos
中。您的存储库返回第一个存储库中的IEnumerable<T>
,并且您在Default.aspx
中的属性返回第二个存储库中的IEnumerable<T>
。它无法运作。
要么在Default.aspx
内更改您的属性以返回IEnumerable<TiendaDeported.Modelos.producto>
,要么进行额外的Select
调用,以便将TiendaDeported.Modelos.producto
映射到TiendaDeported.producto
。