摘要:Entity Framework + CrystalReport 實現主報表與子報表呼叫
弄了好幾天的REPORT 快昏了...卡真久終於用出來了
記得 REPORT 要加入Entity 的實體類別喔!!! (各自放自己的資料表,無多放!!)
Model.SchoolEntities _context = new EntityReport.Model.SchoolEntities(); //初始化 Entity 資料
var Oc_query = from q in _context.OnlineCourse //查詢主報表資料
where q.CourseID == 2021
select q;
var query = from q in _context.Course //查詢子報表資料
select q;
Report.EntityReport rp = new EntityReport.Report.EntityReport(); //實例化Report檔
rp.SetDataSource(Oc_query.ToList()); //主報表SetDataSource
rp.Subreports[0].SetDataSource(query.ToList()); //子報表SetDataSource
this.crystalReportViewer1.ReportSource = rp; //顯示Report