locked
Including an EntityFramework Report into my WPF site RRS feed

  • Question

  • Hello All,

    I have created a WPF project in VS2015, and in this project I make use of Entity Framework (code first) to handle some data requirements for me. The project is really simple, and the data manipulation as provided by EF is great for me now.

    However, I am struggling a bit with getting my report setup properly. I have created a file called Report.rdlc, that is setup to display some data for me, and it correctly references the data objects created by EF. Now my problem is that I do not know how to run the report from my wpf window. I have done the following to try and it to my reporting tab window:

    1. Add to xaml the following namespace:

     xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" 


    2.  Change my tab item to contain the following:

    <!-- Reporting -->
                <TabItem Header="Reporting">
                    <Grid Background="#FFE5E5E5">
                        <WindowsFormsHost HorizontalAlignment="Left" Height="268" VerticalAlignment="Top" Width="487">
                            <rv:ReportViewer x:Name="_reportViewer"/>
                        </WindowsFormsHost>
    
                    </Grid>
                </TabItem>

    In my code behind I have:

            private bool _isReportViewerLoaded;
    
            public MainWindow()
            {
                _reportViewer.Load += ReportViewer_Load;
                InitializeComponent();
            }
    
            private void ReportViewer_Load(object sender, EventArgs e)
            {
            ......................................
            }

    I am having problems with referencing the right stuff in the 

    ReportViewer_Load. I would appreciate some help, as I do not know where to find the DataSet and Adapters, as referenced from a tutorial I followed; Does EF create this for you or not?

    The entire source can be found here: MyProject.

    Thank you.

    Wednesday, March 16, 2016 9:32 AM

All replies

  • Hi harriet_001,

    >>” I do not know where to find the DataSet and Adapters”

    You would need to create such DataSet by yourself. Here’s code sample about “Report Viewer in WPF”, you could refer to it for details.

    You could also using Bing to Search “reportview in wpf”, you would find many tutorials.

    Best Regards,

    Xavier Eoro

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Xavier Xie-MSFT Tuesday, March 29, 2016 4:45 AM
    • Unproposed as answer by harriet_001 Tuesday, March 29, 2016 1:58 PM
    Friday, March 18, 2016 6:52 AM
  • Hi,

    I marked your answer as "unproposed as answer" because it is not an answer, you basically sent me off to some article refering VS2010, and told me to use google to find the answer. 

    I tried that in the first place, and would not have posted here if I had found the answers there. Please read my specifics to the question before giving me a random answer.  


    • Edited by harriet_001 Tuesday, March 29, 2016 2:01 PM
    Tuesday, March 29, 2016 2:00 PM
  • You don't use dataset or adapters if you're using entity framework.

    You build the report against a collection of a specific entity type and then set the datasource to a collection of that type.

    You can see an example which covers sub reports and stuff here:

    https://www.reddit.com/r/csharp/comments/3lo6oy/creating_reports_in_c_with_reportviewer_and/

    But the bit you're probably interested in is:

    private IEnumerable<Order> Orders { get; set; }
    
    var orderSource = new ReportDataSource { Name = "Orders", Value = this.Orders };
    this.reportViewer.LocalReport.DataSources.Add(orderSource);
    Where Orders is a collection of Order, your table in the database is Orders and you built the report against the order type.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Tuesday, March 29, 2016 2:31 PM