Crystal Reports and LINQ
Solution 1
You can convert your LINQ result set to a List
, you need not strictly use a DataSet
as the reports SetDataSource
, you can supply a Crystal Reports data with an IEnumerable
. Since List
inherits from IEnumerable
you can set your reports' Data Source to a List, you just have to call the .ToList()
method on your LINQ result set. Basically:
CrystalReport1 cr1 = new CrystalReport1();
var results = (from obj in context.tSamples
where obj.ID == 112
select new { obj.Name, obj.Model, obj.Producer }).ToList();
cr1.SetDataSource(results);
crystalReportsViewer1.ReportSource = cr1;
Solution 2
The msdn doc's suggest that you can bind a Crystal Report to an ICollection.
Might I recommend a List(T) ?
Solution 3
Altough I haven't tried it myself it seems to be possible by using a combination of DataContext.LoadOptions to make it eager to accept relations and GetCommand(IQueryable) to return a SQLCommand object that preserves relations.
See more info on MSDN Forums.
Comments
-
Martin almost 2 years
Has anyone figured out how to use Crystal Reports with Linq to SQL?