Telerik blogs

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).

CURRENT STATE

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.

OUR REQUEST TO YOU

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.

OBTAINING THE INTERNAL BUILD

Download and install the latest internal build for Telerik Reporting version 7.1.13.726. 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.

clip_image001[4]

GETTING DESIGN-TIME SUPPORT WITH ENTITYDATASOURCE

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.

clip_image002[4]

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

    {

        public AdventureWorksEntities()

            : base("name=AdventureWorksEntities")

        {

        }

       .

       .

       .

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)

            : base(connectionString)

        { }

 

    }

After you build the project, you will have full design-time and preview tab support.

CONCLUSION

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!

Download Telerik Reporting


About the Author

Carey Payette

Carey Payette is a Senior Software Engineer with Trillium Innovations (a Solliance partner), an ASPInsider, a Progress Ninja, a Microsoft Certified Trainer and a Microsoft Azure MVP. Her primary focus is cloud integration and deployment for the web, mobile, big data, AI, machine learning and IoT spaces. Always eager to learn, she regularly tinkers with various sensors, microcontrollers, programming languages and frameworks. Carey is also a wife and mom to three fabulous boys.

Comments

Comments are disabled in preview mode.