Telerik is committed to providing tools that developers need. Recently the engineering team has been hard at work implementing an updated solution to using newer versions of Entity Framework (versions 4 and 5) with Telerik Reporting and more specifically for DBContext models. This will allow you to use both Entity Framework contexts (ObjectContext and DBContext) with Telerik Reporting. This update is a common request and we are ready to deliver. We now have an early internal build that includes support for Entity Framework versions 4 and 5 (we are not currently supporting Entity Framework 6 Beta).
Prior to this early build there was a couple of different approaches to get EF to work with Telerik Reporting, one approach was to use business classes with ObjectDataSource, and the other was to use EntityDataSource with the help of T4 template code generation. We know that these approaches were not ideal, so we are providing a better solution. This is where you come in.
In an effort to ensure that we are serving a solution that meets your needs, we are requesting that you take this new Entity Framework support functionality out for a spin and to let us know your feedback. This feedback can be either good or bad, we want it all, and in return we will offer you up to 10,000 Telerik Points as a reward.
Download and install the latest internal build for Telerik Reporting version 126.96.36.1996. You will need to log into your Telerik account to get to this link if you haven’t already done so. You will also to have to had previously downloaded and installed v7.1.x of Telerik Reporting. Version notes are also available so you can get a clearer understanding of the changes in this build.
NOTE: If you are using a Code-First approach to EF, this section is not required for design-time support.
By default, the DbContext code generator of Entity Framework only includes a default parameter-less constructor. With only a default constructor, EF will try to automatically retrieve the connection string from the application’s configuration file. In our case, we are running Visual Studio at design time (devenv.exe), whose configuration file (devenv.exe.config) does not contain our connection string. In order to have design-time support for Telerik’s EntityDataSource, we will need to add an additional constructor that takes in a connection string. This is quite easily done by adding a partial class to the DbContext with our new parameterized constructor. This allows Telerik Reporting to instantiate the EF DbContext with the value stored in your project configuration.
Let me show you how to add this partial class. For this example, I’ve generated an ADO.NET Entity Model of a few tables from the AdventureWorks database, naming my model “AdventureWorks.edmx”. In the Solution Explorer, expand the source file tree under the model and locate the AdventureWorks.Context.cs, this is where you will see the EF generated DbContext.
If you look at the code, you can see the parameterless constructor. You will also note that the DbContext is typically your model name, appended with “Entities”.
public partial class AdventureWorksEntities : DbContext
We will use this class name to create a new partial class that will include our parameterized constructor. Create a new class, I’ve named mine “AdventureWorksEntitiesPartial.cs” and change the class signature as well as add our constructor as follows:
public partial class AdventureWorksEntities
public AdventureWorksEntities(string connectionString)
After you build the project, you will have full design-time and preview tab support.
Your feedback is extremely important to us, it helps ensure that we deliver the best product possible. Please provide us with your feedback through the Reporting forums and support system by Thursday August 1st at 5PM Eastern and be rewarded. Thank you in advance for your participation – we greatly appreciate it!
Carey Payette is a Developer Advocate. You can follow Carey on Twitter @careypayette or read her personal blog at www.codingbandit.com.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.