none
Accessing the properties of a LINQ EntityRef RRS feed

  • Question

  • This is in Visual Studio 2010 using Microsoft Report Viewer 2010.

    I have a report bound to a LINQ entity called License.  This License entity has an association property (EntityRef) called Licensee.  A Licensee has a Name property.

    When I am in code, I can do this.

    License lic; //Comes from the business logic layer
    
    
    
    string strName = lic.Licensee.Name;
    
    

    Is it possible to do this in the rdlc report file?

    This does not work.

     

    =Fields!Licensee.Value.Name

    Friday, September 3, 2010 1:07 PM

Answers

  • Hi Chris,
    I am afraid that currently the reportviewer does not support such writing. Instead I recommend that you use a Linq query to generate a temp table and bind the result to your report. In your report, you can directly use =Fields!Name.Value.

    For example, I performed a test based on Northwind database. The Customer is an EntityRef property in Order class. Besides the orders information, I also would like to add the ContactName information in the Customer entity to the report. Then you can refer to the following code to bind the data to your report:

          OrderDataContext context = new OrderDataContext(connectionString);
    
          var orderInformation = from order in context.Orders
                      join customer in context.Customers
                      on order.CustomerID equals customer.CustomerID
                      into _customers
                      from _customer in _customers.DefaultIfEmpty()
                      select new
                      {
                        order.CustomerID,
                        order.OrderDate,
                        order.OrderID,
                        _customer.ContactName
                      };
    
    
          this.reportViewer1.LocalReport.ReportPath = "Linq2SQLReport.rdlc";
          this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("CSFMTest_Order", orderInformation));
          this.reportViewer1.RefreshReport();
    
    In my report, I use =Fields!ContactName.Value directly.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, September 6, 2010 7:33 AM
    Moderator