| |
Preface
Most O/R mappers work solely with entities as objects. In a lot of situations this is a great way of dealing with relational data, but
in some situations, especially with read-only lists, it can be cumbersome to create a list of values from two or more related entities. LLBLGen Pro
has solved this by introducing the 'Typed List' feature, which are views on one or more related entities.
This tutorial shows you how to create a Typed List containing a subset of the Order entity fields and the Customer entity's company name field,
and the name of the Employee that handled the Order. This Typed List, which is generated as a typed DataTable class, is then binded to
a datagrid. With other O/R mappers this wouldn't have been possible, with LLBLGen Pro it is a set of easy steps.
The tutorial guides you through the following steps:
- Create a new project. It shows you how to create a project and various aspects of creating a project.
- Add and edit entities. It shows you how to add entities and how to alter several aspects of an entity.
- Add and edit a Typed List. It shows you how to add a typed list and to edit its contents.
- Generating code. It shows you how to generate code from the project you created.
- Adding the project to your VS.NET solution. It shows you how to add the generated project to your
Visual Studio.NET solution.
- Using the typed list. It shows you how to fill the typed list with specific data and to show the typed list in a grid.
Some parts of this tutorial use flash to show actual screen-captures of using LLBLGen Pro. The tutorial uses the Northwind database, shipped
with SqlServer 7/2000/MSDE. The LLBLGen Pro demo can't create a project, but a Northwind project is provided with the demo so you can skip
step 1 and just load the clean Northwind project.
Create a new project
Click here
to view the flash movie about creating a new project.
Add and edit entities
Click here
to view the flash movie about adding entities to the new project, save the project and edit some entity specific information.
Add and edit a Typed List
Click here
to view the flash movie about adding the Typed List 'OrderCustomerEmployee' to the project and to edit its definition.
Generating code
Click here
to view the flash movie about generating C# code for our project.
Adding the project to your VS.NET solution
Click here
to view the flash movie about adding the generated code and its Visual Studio.NET project to an existing Visual Studio.NET solution and to set
the right references.
Using the typed list
Our solution is now ready to use all of the generated code. This tutorial focusses on Typed Lists, so we'll fill our typed list we've just
created, OrderCustomerEmployee, with data and bind it to the datagrid control, called '_theGrid', on our form MainWindow.
The code required to fill the list with data and show it in the grid is given in C# and VB.NET. Required is to have a form with a
datagrid control called '_theGrid'.
Add the following lines to the namespace declarations at the top of the code window for your form:
// C#
using SD.LLBLGen.Pro.ORMSupportClasses;
using Northwind.TypedListClasses;
' VB.NET
Imports SD.LLBLGen.Pro.ORMSupportClasses
Imports Northwind.TypedListClasses
Now we can add the code for filling and binding our typed list. In this tutorial, for simplicity, we add this code to the form's constructor:
// C#
public MainWindow()
{
InitializeComponent();
// create an instance of the typed list
OrderCustomerEmployeeTypedList theList =
new OrderCustomerEmployeeTypedList();
// fill it!
theList.Fill();
// bind it to the grid.
_theGrid.DataSource = theList;
}
' VB.NET
Public Sub New()
InitializeComponent()
' Create an instance of the typed list
Dim theList As New OrderCustomerEmployeeTypedList()
' fill it!
theList.Fill()
' bind it to the grid.
_theGrid.DataSource = theList
End Sub
That's it! When you compile the solution now, the grid will show all orders, the Customer's company name and the Employee's Firstname
and Lastname.
The Typed List's Fill() method has of course overloads to filter on rows, sort the data using database logic, filter out duplicate rows and
limit the amount of rows filled in the Typed List instance. See the LLBLGen Pro documentation for more details on these topics.
|