|
In order to use the result of LINQ query as the data for a report you should use Object Data Provider type of the data source.
The object which the LocateDataSourceEventArgs.Data value should be set to depends on the type of the LINQ query:
If you use LINQ to XML, then the result returned by the LINQ is the object of type IEnumerable<XElement>. In order to use this object as the report data, you should create the collection of the business object from the collection of XElement objects and set the LocateDataSourceEventArgs.Data value to the collection of the business objects. This is possible using the anonymous types feature. Here is the sample: void OnLocateDataSource(object sender, LocateDataSourceEventArgs args) { XElement root = XElement.Load(@"c:\factbook.xml"); var data = from el in root.Elements("country") where (string)el.Attribute("name") == "Russia" || (string)el.Attribute("name") == "United States" select new { Name = el.Element("Name").Value, Population = el.Element("Population").Value }; args.Data = data; }
If you use LINQ to SQL or LINQ to Objects, the the
LocateDataSourceEventArgs.Data value should be set directly to the IEnumerable<BusinessObject> object returned by the Linq query. void OnLocateDataSource(object sender, LocateDataSourceEventArgs args) { NorthwindDataContext db = new NorthwindDataContext(); var data = from c in db.Customers join o in db.Orders on c.CustomerID equals o.CustomerID join od in db.Order_Details on o.OrderID equals od.OrderID select new { c.CustomerID, c.CompanyName, o.OrderID, o.OrderDate, od.UnitPrice, od.Quantity }; args.Data = data; }
Sergey Abakumoff GrapeCity
|