2014-01-25 62 views
1

我有一個屬性無法隱式轉換類型「System.Collections.Generic.IEnumerable要System.Collections.Generic.IEnumerable <TiendaDeportes.producto>

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>'。 存在明確的轉換(您是否缺少演員?)

回答

2

您有兩個名爲producto的類。一個在TiendaDeportes命名空間中,另一個在TiendaDeported.Modelos中。您的存儲庫返回第一個IEnumerable<T>,並且您屬於第二個Default.aspx返回IEnumerable<T>。它不能工作。

要麼改變你的財產裏Default.aspx返回IEnumerable<TiendaDeported.Modelos.producto>或進行其他Select調用映射到TiendaDeported.Modelos.productoTiendaDeported.producto

+0

非常感謝我的朋友。來自墨西哥的問候 – Vesper

相關問題