In this video I’m going to show you how
to bind a report to a database using Express Persistant Objects, or XPO for short.
First, let’s right click on the project and add a new item.
This item is a data item, and we’re going to select the DXperience ORM data model wizard.
Let’s call it Northwind and hit add. We’re going to map to an existing database,
hit next, its already set to the local server name, and let’s select the Northwind database.
Next, let’s select the categories table and hit next.
Remove generate comments, hit next, and finally hit finish.
Notice that it automatically created an object for our categories table.
We’ll go ahead and build, and note that it created a categories object, the designer
object has all the fields available and you can extend the class anyway you want using
the partial class. XPO also created a connection helper in order
to set the default connection settings. OK, great, lets add a report.
To do that, right click, and add a new item, this item is going to be a report class.
We’ll call it category report. Ok, to bind to the objects we’ve created
we’ll go to the datasource and we’ll add a project datasource. We’ll select object
and click next. Next drill down to reports, reports.northwind,
ad select the categories object, then hit finish.
We’ll go to the field list and you can see that all the fields are available. Let’s
drag category name onto the design surface for the report, notice in this case when we
go to preview there is no data available, and the reason why is because the category’s
object has no notion of how to pull data from the database.
We’ll fix that by using scripting. First thing, we’ll go to the solution explorer
and make sure that all of the assemblies are copied local. The reason we’re gonna do
that is so the XPO assembly can be referenced by the script that we’re going to write
now. Next, lets go to the script references section
and add a reference to the XPO assembly that we just copied locally and hit OK
Next we’ll got the scripts and use the ondatasource demanded event to generate the data for the
report. The script has a couple of things that it needs to know about: primarily the
reports section which is the actual assembly we’ve generated, link because we’re going
to use a 2-list method, XPO because that’s where the session comes from, and the reports.northwind
namespace, to actually generate the category’s objects.
Finally we set the default connection using the connection helper, and then we create
the list of objects by creating a new session, we query the category’s object, and generate
a list of them. And then set it to the datasource.
Finally we need to add the system.windows.forms assembly in order to use the binding source
that we created earlier in the designer. And that’s it!
You can see that we can preview items directly from XPO.
In this video I showed you how to bind a report to an XPO generated class that binds to the
Northwind Database. Thanks for watching, and thank you for choosing