2012-03-14 83 views
2

我有以下Linq,它鏈接到一個報告。報告VS 2010,深入研究集錦

恢復它是一個帳單的報告,但票據有多個產品,所以我有一個ICollectionProducts。這個想法是在單個報表中使用鑽取(嘗試避免子報表)來顯示每個帳單的多個Products

public class BillsDataSet 
{ 
    public int IDGestion { get; set; } 
    public string Comentario { get; set; } 
    public ICollection<BillProduct> Products { get; set; } 
    public decimal Monto { get; set; } 
    public string Personal { get; set; } 

    public static List<BillsDataSet> BillsPorFecha(DateTime dtFechaInicial, DateTime dtFechaFinal) 
    { 
     Context db = new Context(); 

     List<BillsDataSet> BillsDataSet = (from p in db.Bill 
               select new BillsDataSet() 
               { 
                IDGestion = p.IDBill, 
                Comentario = p.Historial.FirstOrDefault().Comentario, 
                Products = p.BillProduct, 
                Monto = p.Total, 
                Personal = p.Historial.FirstOrDefault().CodigoEmpleado 
               }).ToList(); 
     return BillsDataSet; 
    } 
} 

我越來越對網頁報告這個錯誤... I'm getting this error on the web page report

我想實現的是對Products下鑽隱藏/顯示所有相關的法案Products ...

+0

這可能是因爲延遲加載「產品」。 – 2012-03-14 13:24:24

+0

你應該看看我的問題http://stackoverflow.com/questions/9637818/handle-this-object-datasource-on-reporting-services – Jorge 2012-03-14 14:11:35

回答

0

請嘗試以下

public static List<BillsDataSet> BillsPorFecha(DateTime dtFechaInicial, DateTime dtFechaFinal) 
{ 
    Context db = new Context(); 

    List<BillsDataSet> BillsDataSet = (from p in db.Bill 
              select new BillsDataSet() 
              { 
               IDGestion = p.IDBill, 
               Comentario = p.Historial.FirstOrDefault().Comentario, 
               Products = (from b in db.BillProduct where b.product_id == p.IDBill select new BillProduct()).ToList() as ICollection<BillProduct>, 
               Monto = p.Total, 
               Personal = p.Historial.FirstOrDefault().CodigoEmpleado 
              }).ToList(); 
    return BillsDataSet; 

}