xpo-403337-design-time-features-data-model-wizard-faq.md
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:
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:
In the Model Designer , select the class or field and edit its Custom Attributes property.
Click the ellipsis button in the Property window to invoke the dialog window.
In the dialog window, type the attribute name and arguments. Use the full type name of the attribute, including namespaces.
Q: How to create a one-to-many relationship (association)?
A: Do the following:
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
}
}
Public Class CSharpClass
Protected Overrides Sub OnChanged(ByVal propertyName As String, ByVal oldValue As Object, ByVal newValue As Object)
MyBase.OnChanged(propertyName, oldValue, newValue)
If IsLoading Then Return
If Equals(propertyName, "trigger property name") Then
'your business logic
End If
End Sub
End Class
Solution 2.
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:
In the ORMDataModel window, right-click the root Data Model item and select the “ Add New External Type “ command.
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.
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:
Right-click the class box and select the “ Add new Composite Property “ command from the context menu.
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.
For the newly created property, set Key to True:
Q: How to create a class mapped to a database view?
A: Use the “Generate classes for views” option on the first wizard page.
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:
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.
If this does not resolve the issue, check whether the DevExpress ORM Data Model Wizard extension is enabled in the Manage Extensions menu.
Q: How to collect diagnostic data for the Data Model Wizard installation errors?
A: Collect and send us the following files:
C:\Program Files\DevExpress 25.2\Components folder. Please refer to the following article for details: Troubleshoot Installation Errors./Log key. See the following article for additional information: Troubleshooting Extensions with the Activity Log.If the DevExpress ORM Data Model Wizard extension is not installed, try to re-install DevExpress components.
See Also