When creating an empty .Net Core console project from scratch (not from template) and adding simple report, i have an Entity Framework source item in report wizard, but there are no contexts prepared yet.
After adding a Microsoft.EntityFrameworkCore.SqlServer NuGet package (or by simply referencing a .Net Standard class library with a defined context) and running the wizard again there is no Entity Framework source.
How do i connect my report to EF Core data context?
Entity Framework Core as a data source for XtraReports is missing from Report Design Wizard in .Net Core console project
Answers approved by DevExpress Support
Hi Kasbolat,
As you probably know, DBContext was never designed with the design-time support in mind. We're doing quite a lot of work (or should I rather say hacks) to avoid this limitation so you can preview your document right in the preview tab of the Visual Studio Report Designer. For example, the instantiation of DBContext "as is" will immediately fail because it will inspect the configuration file of the denenv.exe process and not the configuration file of your actual project.
Unfortunately, the latest version of the EF Core framework introduces some change, which makes it impossible to instantiate context in our designer that's written against the full framework (our REPX editor uses the full framework even if you work on an ASP.NET Core project). So, for example, if you downgrade your package to version 2.0, you'll see the corresponding Data Source Wizard option again. It is possible that the situation will improve with the official release of .NET Core 3.0, but right now I can't give any promises or tell you the estimate.
In the meantime, consider using the following workarounds:
-
If you're using the End-User Web Report Designer and would like to populate it with a predefined EFDataSource instance, create it in code as it's illustrated in this KB article: How to create Data Access Library data sources at runtime.
-
Use the Object Binding approach.
This approach implies two main steps:
- Exposing the schema of your persistent entity at design time and designing a report against it: Bind a Report to an Object Data Source
- Replacing the datasource with the actual in-memory collection of loaded objects at runtime:
C#var dbContext = new NWindContext();
var query = (from p in dbContext.Customers
select p).Include("Products").ToList<Customer>();
XtraReport1 myReport = new XtraReport1();
myReport.DataSource = query;
I hope this clarifies the situation. Should there be further questions, let us know.
Regards,
Yaroslav
Hi Kasbolat,
It is possible that the nested DetailReportBand is still bound to the original ObjectDataSource component. That is, you replace the datasource of the root XtraReport, but not any of the embedded subreports it contains. To resolve the issue, I suggest that you modify the original component instance rather than replacing it. Consider the following code:
C#(report.DataSource as ObjectDataSource).DataSource = new ReportData();
>>How to display single properties along with lists in a report?
This is not really possible from the technical perspective as we support binding to lists only: Binding Data to Reports | List Object. It's OK to have just one object in the list, but it must be a collection. If you were to bind your object instance directly, you'd immediate face the discussed above exception:
C#ReportData reportData1 = new ReportData();
report.DataSource = reportData1; //exception
report.DataSource = new List<ReportData>() { reportData1 }; //ok
Anticipating a possible question, I'd like to clarify that ObjectDataSource creates a dummy generic collection behind the scenes, so that's why it's not strictly necessary to wrap your business object if you use this component. XRRichText document model is really heavy and allocates a lot of objects.
Regards,
Yaroslav
This makes things more clear now.
Thank you very much for your time and support.
I've managed to solve my case using sub-details report, which is bound to one of my collections.
Seems to work so far.
You're very welcome! Should further questions arise, let me know, I'll be happy to follow up with you.
Have a good day.
Regards,
Yaroslav