none
Creating report with LINQ as data source RRS feed

  • Question

  • Hi folks,

    I am trying to create an embedded report in visual studio 2010 SP1 that uses a LINQ data query to retrieve the data.  The issue I am having is that I cannot get the report to pick up either by data context (dbml) class or my  class containing some custom query methods.

    I have a class called QueryData that contains a method  IQueryable<bob> GetBobData() { return IQueryable<bob> from dcBob.BobsData select new Bob {...} }

    I have also added a datacontext called dcBob.

    When I create a new report and try to add a dataset, it prompts me for a new connection string to the database (it presents those in server explorer) completely ignoring the datacontext or my query class.

    I have had this working before in another application, but I cannot remember what the work-around is to make the report designer correctly pick up the data context or query method. Does anyone have any ideas.

     

    I have tried using the reportviewer to create a new report and configure a LINQ data source, however, when I select my custom method, it greys out the 'next' button.

     

     


    Friday, May 6, 2011 4:34 AM

Answers

  • I eventually worked out the solution.

    The class has to be in the root of the solution and needs to have the same namespace.  One then needs to compile the solution before creating the report.  The class will be visible when creating a data source for the report.

    • Marked as answer by AndyW2007 Monday, January 23, 2012 10:56 PM
    Monday, January 23, 2012 10:56 PM

All replies

  • Hmmm, the report won't suck data from a method in the way you are thinking. It doesn't run or execute methods.

    Design the report usng an object datasource, selecting a dbml class entity (e.g. Customer, Order) from the project the dbml file is in, then you get access to the object's properties as fields for use on the report to design it.

    In code/runtime you need to pass a populated entity / list of entities to the ReportViewer's LocalReport as a datasource to display the data.

    Friday, May 6, 2011 10:28 AM
  • I eventually worked out the solution.

    The class has to be in the root of the solution and needs to have the same namespace.  One then needs to compile the solution before creating the report.  The class will be visible when creating a data source for the report.

    • Marked as answer by AndyW2007 Monday, January 23, 2012 10:56 PM
    Monday, January 23, 2012 10:56 PM