Skip to main content
All docs
V23.2

FAQ: ORM Data Model Designer and Wizard

  • 8 minutes to read

Q: The “Specify database connection settings” dialog showed errors after I opened the Database editor*:

“Could not load file or assembly {AsssemblyName} or one of its dependencies”* and “Could not load type {TypeName}Connection”, where {AsssemblyName} and {TypeName} are ADO.NET-specific assemblies and types.

Examples:

  • “Could not load type MySql.Data.MySqlClient.MySqlConnection”,
  • “Could not load type NpgSql.NpgSqlConnection”,
  • “Could not load type FirebirdSql.Data.FirebirdClient.FbConnection” or “unable to load DLL ‘fbembed’”
  • “Could not load System.Data.SQLite.SQLiteConnection” or “Connection Failed”, etc.

The project’s Bin folder contains all the required database binaries, and my projects have the corresponding assembly references or NuGet packages.

How to make this work at design time?

A: The ORM Data Model Wizard is a Visual Studio extension. Design-time extensions cannot access assemblies from project references or the project’s output directory.

To make design-time tools work correctly, register the required database DLLs in the Global Assembly Cache (GAC).

If this does not resolve the issue, obtain the design-time error details as described in the following articles:

You can use information from the callstack, inner exceptions, and logs to identify possible causes and how to resolve this issue.


Q: Can I edit the source code produced by the designer?

A: Yes, you can. Refer to the following article for more information: Create partial declarations for manual editing.


Q: How can I decorate my classes and properties with attributes?

A: Do the following:

  1. In the Model Designer, select the class or field and edit its Custom Attributes property.
  2. Click the ellipsis button in the Property window to invoke the dialog window.

    model designer custom attributes

  3. In the dialog window, type the attribute name and arguments. Use the full type name of the attribute, including namespaces.

    model designer custom attributes window


Q: How to create a one-to-many relationship (association)?

A: Do the following:

  1. Create a reference-type field in the class on the “many” side. If you already have a field that contains a key value of another class (a foreign key), change the field type to a class reference.
  2. Select the Association tool from the toolbox and draw a line from the “one” side class to the “many” side class. Alternatively, right-click the “one” side class, select the “Create One-to-Many Relationships“ command from the context menu, and select the opposite class in the dialog.

Q: My XPO-based application uses an existing database. Can I use the wizard to create a model from this database if I want to re-use it in another application?

A: We recommend that you do not generate a new model for a database that was created by XPO. Instead of generating a new model, share the assembly where persistent classes are declared among all applications that connect to the database.

Details. XPO creates the XPObjectType table that stores the full class name and assembly name for each persistent class used in Inheritance Mapping. This information is used to determine the type to instantiate. Newly generated classes are declared in a different namespace and assembly, and original assemblies where they were declared are not available: XPO will not be able to load such objects.


Q: How to implement business logic that is triggered when a property value is changed?

A: Solution 1. In the partial class file (YourClassName.cs), override the OnChanged method as follows:

protected override void OnChanged(string propertyName, object oldValue, object newValue) {
    base.OnChanged(propertyName, oldValue, newValue);
    if (IsLoading) return;
    if (propertyName == "trigger property name") {
        //your business logic
    }
}

Solution 2.

  1. Exclude or remove the property with custom logic from the visual data model and save your changes to update the autogenerated code.
  2. Re-declare the removed property in the partial class and implement custom logic in the property setter.

Q: How to inherit a class from an existing class declared in code or another library?

A: The designer can retrieve type information from an assembly only. If you have a class declared in code, build the solution and follow the instructions in the following secton: Inherit a Class from an Existing Class Declared in Another Library


Q: How to create a property of an enumeration, image, or another non-persistent type?

A: Do the following:

  1. In the ORMDataModel window, right-click the root Data Model item and select the “Add New External Type“ command.

    orm data model designer add external type

  2. Select an external type and specify its Name and Namespace in the Properties window. The external type is shown in the Column Type selection combo box for class fields.

    orm data model designer add external type properties

Use a Value Converter for types that XPO cannot store by default. For more information, refer to the following article: How do I declare an image property in the ORM Data Model Designer.


Q: How to create a composite (compound) key?

A: Do the following:

  1. Right-click the class box and select the “Add new Composite Property“ command from the context menu.

    data model designer add composite key

  2. In the pop-up dialog, select properties you want to include in the compound key and specify a name for the newly created key property.

    data model designer select properties for a composite key

  3. For the newly created property, set Key to True:

    data model designer add composite key


Q: How to create a class mapped to a database view?

A: Use the “Generate classes for views” option on the first wizard page.

xpo data model wizard generate classes for views

The wizard generates non-persistent classes for views because views do not have primary keys. To use this class to retrieve data, set its Persistent property to True and declare a key. Refer to the following article for information on how to choose or create a key property for a view: How to map a persistent object to a view

To declare a key for a class, select the field and set its Key property to True.


Q: I want to use the wizard to generate a model but continue development in code only. What should I do?

A: The Model Designer updates the source code files when you save the model. You can edit generated classes if you are not going to use the designer after class generation. To avoid losing changes made to the source code, you can delete the model files (*.xpo and *.xpo.diagram).


Q: Why are certain tables and columns grayed out (disabled) in the wizard and I cannot import them?

A: Tables and columns are grayed out when they do not meet XPO requirements. For example, a table does not have a declared primary key or a column type is not supported. You can hover the mouse pointer over an item for information on why it is disabled.


Q: When I update the model from the database, classes in my model are rearranged automatically again. How can I avoid losing my layout customizations?

A: Click in the designer surface to select the entire model and set Freeze Layout to True in the Properties window.


Q: My data model is huge and it is difficult to use the visual diagram to navigate to classes. Can I search and navigate by class name?

A: You can use the tree’s Data Model | Classes node in the ORMDataModel window.

This tree supports the following functionality:

  • Keyboard search by first node letters.
  • A double click on a class node centers a corresponding element in the visual diagram.

orm-designer-ormdatamodel-window


Q: I received the “‘ORMDataModelPackage’ package did not load correctly” error after Visual Studio loaded a project. As a result, the *.xpo file extension is not recognized and the visual designer is not shown (only a text file). The Activity Log contains the following information: “CreateInstance failed for package [ORMDataModelPackage] (Could not load file or assembly Microsoft.VisualStudio.Modeling.Sdk.Shell)” . What are the prerequisites for the XPO visual designer to work in Visual Studio?

A: The ORM Model Designer’s visual diagram uses the Visual Studio Modeling SDK. This Visual Studio component is typically installed as a part of popular workloads and individual components such as Linq to SQL Tools, Entity Framework 6 Tools. If you have a customized Visual Studio installation, make sure that Modeling SDK or any dependent components are installed.

To check whether this component is installed, search for the Modeling SDK component in Visual Studio Installer.

Visual Studio Modeling SDK

If this does not resolve the issue, check whether the DevExpress ORM Data Model Wizard extension is enabled in the Manage Extensions menu.

orm wizard manage extensions


Q: How to collect diagnostic data for the Data Model Wizard installation errors?

A: Collect and send us the following files:

  1. The DevExpress installer log file located in the C:\Program Files\DevExpress 23.2\Components folder. Please refer to the following article for details: Troubleshoot Installation Errors.
  2. The Visual Studio Activity Log. To obtain it, run the Visual Studio instance from the command line with the /Log key. See the following article for additional information: Troubleshooting Extensions with the Activity Log.
  3. Make sure that the DevExpress ORM Data Model Wizard extension is installed and not disabled. To do this, click the Extensions/Manage Extensions menu item, select the Installed tab in the Manage Extensions window, and find the package mentioned above in the list.

If the DevExpress ORM Data Model Wizard extension is not installed, try to re-install DevExpress components.

See Also