I love getting interesting questions thrown my way, it gives me the opportunity to not only learn something new, but also find out what Crystal Reports users are trying to do, and just how functional Crystal Reports is.
The question that crossed my path a couple of times is one that has been showing up in our forums, how to build reports off of the Entity Data Model (EDM) Framework.
Not having any idea what this was or why one would want to use it I did some searching and came across this web site that had a great introduction to this http://www.devx.com/codemag/Article/36133/0/page/1
I followed this just to the point where I could display the Northwind Customers table in a datagrid. Then I went and tried to create a report off of the EDM Customers table, and it was amazingly easy to do.
I am going to assume when you are reading this you already have your EDM already created, if you haven’t and don’t know where to begin, I suggest the link above.
To report off of this is two steps, first you have to create the report:
- Right-Click your project and select Add New Item.
- Under Reporting select Crystal Report and click Add.
- Click OK to use the Report Wizard.
- Expand Project Data
- Expand .NET Objects
- You should now see a list of your available tables in your EDM
- Select a table and add it, in my case I selected Customers
- Click Next and continue to go through the wizard.
The second thing you need to do is set datasource at runtime. This is simple as creating an instance of your EDM in code, and calling the report’s SetDataSource method like this:
// Create an instance of the Customers table
EntityModel.Customers emCustomers = new Customers();
// Create and instatiate strongly-typed report
CrystalReport1 MyCrystalReport1 = new CrystalReport1();
// Set the report’s datasource to my EDM and then view
crystalReportViewer1.ReportSource = cr;
As you can see this is fairly simple to do.