IQueryable queries are executed when iterated. You are disposing the context before the query is run, thus the dispose context error. also there is no reason to call dispose in using block. try:
using (DataContext context = new DataContext())
{
var dayRegime = context?.DayRegimes.Where(x => x.DayId == _dayRegime.DayId);
ReportRegime1.LocalReport.DataSources.Add(new ReportDataSource
{
Name = "DataSet2",
Value = dayRegime
});
ReportRegime1.SetDisplayMode(DisplayMode.PrintLayout);
ReportRegime1.LocalReport.EnableExternalImages = true;
ReportRegime1.Refresh();
ReportRegime1.RefreshReport();
}
if the report will re-query internally, you can still get the error. then just run query first:
using (DataContext context = new DataContext())
{
var dayRegime = context?.DayRegimes.Where(x => x.DayId == _dayRegime.DayId).ToList();
ReportRegime1.LocalReport.DataSources.Add(new ReportDataSource
{
Name = "DataSet2",
Value = dayRegime.ToList() // run query before passing
});
ReportRegime1.SetDisplayMode(DisplayMode.PrintLayout);
ReportRegime1.LocalReport.EnableExternalImages = true;
ReportRegime1.Refresh();
ReportRegime1.RefreshReport();
}