Issue when using Visual Studio Report Designer with Linq to SQL data source

I don't expect to get a great answer from this, so if you had experience with this any input would be appreciated.

I am trying to use Visual Studio Report Designer with Linq to SQL data source, I have no experience with Visual Studio Report Designer.

If I go through the wizard and use the data source object, I can get a simple report that lists one entity type (i.e. sql table). My questions are how to get a report for accepting complex Linq queries using Joins, Sums, etc. With anonymous return type. If I try to do this, at the moment I am getting a compilation error from the report designer when I try to use dot notation or aliases to get the fields I need to reference in the query results. I think it has something to do with the designer expecting the same type that was specified in the wizard ...

Mistake: -

Report item expressions can only refer to fields in the current scale dataset or, if within a population, a specified dataset region.

Perhaps I'd be better off using DataSets?

+1


source to share


1 answer


Write a simple class containing all the properties your report needs (call it, for example, MyData). Use simple .NET types for each property: string, int, etc.

Write another class using the GetXxx method that returns IEnumerable<MyData>

. This Get method should return the results of your Linq query. You can do .ToList () before returning to get the list in memory, which allows you to close the connection before returning.

Compile.



Now open your report designer (in the same solution) and you should see MyData listed in the Data Sources window using the Get method you wrote.

If you drag fields from this data source into Report Designer, and then access this report from the new ReportViewer control, the ObjectDatasource object will be automatically created and bound for you.

Hope it helps!

+2


source







All Articles