This is my code:
public class JobsRepository:BaseNewsletterRepository
{
public IEnumerable<Job> GetJobs()
{
var jobs = Newsletterctx.Jobs.Include("Info").OrderBy(o => o.JobID);
return jobs.AsEnumerable();
}
}
public class BusinessNewsletter
{
public static IEnumerable<Job> GetJobs()
{
using (JobsRepository jobsRepository = new JobsRepository())
{
return jobsRepository.GetJobs();
}
}
}
rptJobs.DataSource = BusinessNewsletter.GetJobs();
rptJobs.DataBind();
When I try to bind I get error:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
Is the only solution, to cast and return List in BusinessNewsletter class?
public static IList<Job> GetJobs()
{
IList<Job> job;
using (JobsRepository jobsRepository = new JobsRepository())
{
job = jobsRepository.GetJobs().ToList();
}
return job;
}
Another related question:
How can I retrieve and bind data to a repeater without specifing a specifc type (List<type>
or IEnumerable<type>
)
I need it in case where I return specific object like this:
var specificJob = (from job in Newsletterctx.Jobs.Include("Info")
select new { ID = job.JobID, EmailId = job.Info.PreparedEmailID });
I must create specific class just for that object?