This is a migrated thread and some comments may be shown as answers.

Determine when to dispose EntityDataSource context with HTML5 viewer

2 Answers 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tam
Top achievements
Rank 1
Tam asked on 03 Jun 2014, 02:00 AM
Hi, 

I'm using EntityDataSource. The context assigned to datasource is not a type class but a dbcontext instance as my application is managing the dbcontext life cycle on its own. Since the report viewer I'm using is HTML 5 viewer, I have not found a way to determine when the report has been rendered completely. 

My question is, how can the application be notified when Telerik report rendering is done with the dbcontext, so that it can safely dispose the context. 

Thank you in advance. 

2 Answers, 1 is accepted

Sort by
0
KS
Top achievements
Rank 1
answered on 03 Jun 2014, 01:34 PM
Hi,

The context is destroyed automatically when the entityDataSource finishes - http://www.telerik.com/help/reporting/entitydatasource-maintaining-the-lifecycle-of-the-objectcontext.html

-KS
0
Tam
Top achievements
Rank 1
answered on 04 Jun 2014, 02:01 AM
Hi KS, 

The context is only destroyed automatically when entityDataSource is created from a type class, as clearly stated by the doc you just link, not if you assign an instance to the context source. 

If you have already implemented your own mechanism for maintaining the lifecycle of the ObjectContext/DbContext you can continue using the EntityDataSource component. In this case however you need to specify a live instance of yourObjectContext/DbContext to the Context property as demonstrated here:
Telerik.Reporting.EntityDataSource entityDataSource = new Telerik.Reporting.EntityDataSource();
AdventureWorksEntities context = new AdventureWorksEntities();
 
entityDataSource.Context = context;
entityDataSource.ContextMember = "Products";
 
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
 
report.DataSource = entityDataSource;
 
// You have to dispose the Context explicitly when done with the report.
context.Dispose();





Tags
General Discussions
Asked by
Tam
Top achievements
Rank 1
Answers by
KS
Top achievements
Rank 1
Tam
Top achievements
Rank 1
Share this question
or