Example T275059
Visible to All Users

XAF - How to create and set up an XtraReport report for exporting to a Stream in a non-XAF application

This example illustrates how to access an XAF report stored in the database and populate it with data in a non-XAF application.

Since XAF stores reports in the database and XAF reports use Object Spaces to retrieve data from the database, it is necessary to connect to the XAF database and create an Object Space to use XAF reports in a non-XAF application.

Implementation Details

  1. Create a custom class that implements the IObjectSpaceProviderFactory interface. Please refer to the CustomObjectSpaceProviderFactory.cs file for implementation details. This class is used as a service to create IObjectSpace objects on demand.
  2. Create the ServiceCollection to register required XAF services and your CustomObjectSpaceProviderFactory service.
  3. Use the IReportExportService service to load and prepare a report.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/ExportReportEF/ExportXAFReport/CustomObjectSpaceProviderFactory.cs
C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Core; using DevExpress.ExpressApp.EFCore; using ExportReportEF.Module.BusinessObjects; using Microsoft.EntityFrameworkCore; namespace MyApp // Note: actual namespace depends on the project name. { class CustomObjectSpaceProviderFactory : IObjectSpaceProviderFactory { const string connectionString = @"Integrated Security=SSPI;Pooling=false;Data Source=(localdb)\mssqllocaldb;Initial Catalog=ExportReportEF"; public IEnumerable<IObjectSpaceProvider> CreateObjectSpaceProviders() { return new IObjectSpaceProvider[] { new EFCoreObjectSpaceProvider<ExportReportEFEFCoreDbContext>((builder, _) => { builder.UseSqlServer(connectionString).UseChangeTrackingProxies(); }) }; } } }
EFCore/ExportReportEF/ExportXAFReport/Program.cs
C#
using Aqua.EnumerableExtensions; using DevExpress.ExpressApp.Core; using DevExpress.ExpressApp.Core.Services; using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp.ReportsV2; using DevExpress.Persistent.BaseImpl.EF; using ExportReportDemo.Module.BusinessObjects; using Microsoft.Extensions.DependencyInjection; namespace MyApp // Note: actual namespace depends on the project name. { internal class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); ServiceCollection serviceDescriptors = new ServiceCollection(); serviceDescriptors.AddXafCore(); serviceDescriptors.AddXafReportingCore(); serviceDescriptors.AddScoped<IObjectSpaceProviderFactory, CustomObjectSpaceProviderFactory>(); IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); var typesInfo = serviceProvider.GetRequiredService<ITypesInfo>(); InitTypesInfo(typesInfo, serviceProvider.GetRequiredService<IObjectSpaceProviderFactory>()); RegisterBOTypes(typesInfo); IReportExportService reportExportService = serviceProvider.GetRequiredService<IReportExportService>(); using var report = reportExportService.LoadReport<ReportDataV2>(data => data.DisplayName == "Employees Report"); reportExportService.SetupReport(report); report.ExportToPdf("testEFCore.pdf"); Console.WriteLine("Done"); } static void InitTypesInfo(ITypesInfo typesInfo, IObjectSpaceProviderFactory osProviderFactory) { var osProviders = osProviderFactory.CreateObjectSpaceProviders(); osProviders.ForEach(osProvider => ((TypesInfo)typesInfo).AddEntityStore(osProvider.EntityStore)); } static void RegisterBOTypes(ITypesInfo typesInfo) { typesInfo.RegisterEntity(typeof(Employee)); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.