[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Expand]Getting Started
 [Expand]Fundamentals
 [Expand]Feature Center
 [Collapse]Concepts
   Basics of Creating Persistent Objects for Existing Data Tables
   Creating a Persistent Object
   Creating a Session
   Creating an XPCollection
   Custom Collection Types
   Deferred and Immediate Object Deletion
   Explicit Units of Work
   Filtering Basics
   Generating Persistent Objects for Existing Data Tables
   How to: Add Persistence to an Existing Hierarchy by Changing the Base Inheritance
   How to: Add Persistence to an Existing Hierarchy by Using Session-less Persistent Objects
   How to: Connect to a Data Store
   Inheritance Mapping
   Nested Units of Work
   NULL Value Handling Specifics
   Optimistic Concurrency Control
   Pageable Collections
   Property Descriptors
   Relationships Between Objects
   Saving Persistent Objects
   Simplified Criteria Syntax
   Simplified Property Syntax
   Sorting Basics
   Using Explicit Transactions
   Using Transactions
   Value Converters
   Working with Sessions
   XPCollection Concepts
   XPDataView Concepts
   XPO Classes Comparison
   XPView Concepts
 [Expand]Design-Time Features
 [Expand]Examples
 [Expand]Member Tables
 [Expand]API Reference
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Generating Persistent Objects for Existing Data Tables

XPO gives you the ability to generate persistent objects for your existing databases using only a few mouse clicks. It provides a design-time wizard that allows you to generate persistent objects for one or more data tables in your database at the same time. It is only needed to specify connection settings to the database, and select target tables and columns. The wizard will automatically generate persistent objects for the selected tables.

Please refer to the Basics of Creating Persistent Objects for Existing Data Tables topic for information on how to implement persistent classes manually.

Note

Data tables whose primary keys are composed of several columns are not supported by the wizard. These tables are neither displayed nor processed by the wizard.

Expanded Step by Step Instructions

  1. Select the Add | New Item... command from the context menu in Solution Explorer.

  2. Select the DevExpress ORM Data Model Wizard item in the invoked dialog window, specify the data model name (e.g., MyDataModel) and click Add.

  3. In the invoked Data Model Wizard, select Map to an existing database and click Next. The wizard will ask you to specify connection settings to the database containing a target data table(s):

    Multiple database systems (MS SQL Server, DB2, MySql, Firebird, etc.) are supported by the wizard. Use the Provider combo box to select the required database type. Note that the corresponding database provider assembly must be available on your machine, otherwise the wizard will fail.

    Click Next after connection settings have been specified.

    Note

    If the wizard throws an error such as "Could not load type MySql.Data.MySqlClient.MySqlConnection", "Could not load type NpgSql.NpgSqlConnection", unable to load DLL 'fbembed' etc., then ensure that you have the required database provider assembly installed. Assemblies required by XPO data store adapters are listed in the Database Systems Supported by XPO topic. You need to put the required DLLs in a place where they can be found by the Visual Studio process. You can install .NET assemblies to the Global Assembly Cache (GAC) and copy the required native DLLs (if any) to %SystemRoot%\System32, to make them available globally.

  4. In the next step, the wizard displays a list of tables that can be mapped to persistent objects.

    Select a table(or tables) to be mapped to a persistent object (or to persistant objects), and for each table select columns that will be mapped to the persistent object's properties. For unchecked columns, persistent properties will not be generated.

    Click Next after the required tables and columns have been selected.

  5. The names of persistent classes and their properties will match the names of selected tables and their columns. You can add/remove custom prefixes and suffixes, and change the case style of names (e.g., capitalize names automatically). You can also preview the resulting names immediately, and manually edit them later in the Data Model Designer. The classes and properties with modified names will still be mapped to the corresponding tables and columns using the PersistentAttribute attribute.

    Click Next, and then click Finish to close the wizard. Click the File | Save All menu item in the Visual Studio toolbar to generate persistent classes. The generated data model will be opened in the Data Model Designer.

Note

If you do not want to use the Data Model Designer and prefer to edit generated classes manually, do the following:

  • In the wizard, uncheck the Create partial declarations for manual editing option. As a result, partial declarations will not be generated and a single file will be created for each class.
  • After the wizard is completed, remove the generated MyDataModel.xpo file (here, "MyDataModel" is the name you specified in step 2 above).
  • Use classes in the MyDataModelCode folder as regular Code First classes - make required modifications in code manually.

Note

You can try the functionality described here in the Querying a Data Store | Generating Persistent Classes for an Existing Database section of the XPO Tutorials demo (C:\Users\Public\Documents\DevExpress Demos 18.2\Components\WinForms\Bin\XpoTutorials.exe).

Expanded See Also

Is this topic helpful?​​​​​​​