Current filter:
                                You should refresh the page.
                                  • Q:  I received errors in the "Specify database connection settings" dialog after opening the Database editor*: "Could not load file or assembly XXX or one of its dependencies"*   and "Could not load type YYYConnection" where XXX and YYY are ADO.NET-specific assemblies and types respectively. 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.
                                    I already have all the required database binaries in the project's Bin folder, 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 - they are only used during the build.
                                    To make design-time tools work here, it is important to put the required DLLs in a place where the Visual Studio process can find and load them - Global Assembly Cache (GAC). Consider the following solutions:
                                        1.  Find and run the required ADO.NET provider Windows/MSI installer - it will usually install everything into GAC automatically. Examples: You can find more if you search by "ZZZ ADO.NET connector download" where ZZZ is your database name.
                                        2.  Manually copy the required native DLLs (if any) to GAC or %SystemRoot%\System32, to make them available globally. Assemblies required by XPO data store adapters are listed in the Database Systems Supported by XPO topic.
                                        3.  If this does not help, obtain the exact design-time error details as per the How to obtain a design-time exception call stack or Assembly Binding Log Viewer (Fuslogvw.exe)  articles and act based on the message, callstack, inner exceptions and logs accordingly. It is likely that you will need to search public community resources like StackOverFlow or database-related forums and documentation.

                                    Q: Can I edit the source code produced by the designer?
                                    A: The wizard has the "Create partial declarations for manual editing" checkbox on the last page (enabled by default). When this option is enabled, the wizard creates two files for each class: classname.cs and classname.designer.cs. The former is offered for user code and can be modified freely. The latter is updated with generated code every time the model is saved. So, it is better not to touch this file, at least if you plan to edit the model in the designer.
                                    Note that you may need to click the "Show All Files" button in the Solution Explorer window to see both files, because some files are hidden in VB.NET projects by default.

                                    Q: How can I decorate my classes and properties with attributes?
                                    A: You can do this in the designer by selecting the class or field and clicking the ellipsis button in the Custom Attributes property. In the dialog window, type the attribute name and arguments. Use the full type name of the attribute, including the namespace.

                                    Q: How to create a one-to-many relationship (association)?
                                    A: First, you need to create a reference-type field in the class on the "many" side of the relation. 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. Then, 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: I have an existing database used by my XPO-based application. Should I use the wizard to create a model from this database to use it in another application?
                                    A: We recommend that you avoid generating a new model for a database that was created by XPO. The problem is that XPO creates the XPObjectType table and stores the full class name and the assembly name in it for each persistent class used in Inheritance Mapping to determine the type to instantiate. Since newly generated classes are declared in a different namespace and assembly, and original assemblies where they were declared are not available, XPO won’t be able to load such objects. So, instead of generating a new model, share the assembly where persistent classes are declared among all applications that connect to the database.

                                    Q: How to implement business logic triggered when a property value is changed?
                                    A: Usually, you would put this logic into the property setter, but since it isn’t recommended to modify the generated code, you should use a different approach. In the partial class file (YourClassName.cs) dedicated to user code, 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 } }

                                    Alternatively, you can exclude or remove the required property from the visual data model, save your changes so that the auto-generated code is updated and finally re-declare the removed property in the partial class manually.

                                    Q: How to inherit my class from an existing class declared in code or another library?
                                    A: The designer can retrieve type information from an assembly only. So, if you have a class declared in code, you need to build it. Then, right-click the designer surface and select the "Add Assembly" command. In the file open dialog, locate the assembly that contains persistent classes, open it, and select classes you want to import into the model. Imported classes will appear in the mode, but they cannot be modified, and no code is generated for them. Now you can use the Inheritance tool from the toolbox to make your declared class inherit from the imported class. The imported class will also appear in the Column Type selection combo box, so you can create a reference property in your class, which will point to the imported class.

                                    Q: How to create a property of an enumeration, image, or another  non-persistent type?
                                    A: In the ORMDataModel window, right-click the root Data Model item and select the "Add New External Type" command. Then, select the created external type and specify its Name and Namespace in the Properties window. The external type will appear in the Column Type selection combo box of class fields. Note that for types that XPO cannot store by default, you need to use a Value Converter. Also refer to the How do I declare an image property in the ORM Data Model Designer article.

                                    Q: How to create a composite (compound) key?
                                    A: First, you need to create fields that will comprise the compound key, if they do not exist yet. Then, right-click the class box and select the "Add new Composite Field" command from the context menu. In the popup dialog, select fields you want to include in the compound field.

                                    Q: How to create a class mapped to a database view?
                                    A: The wizard has the "Generate classes for views" checkbox on the first page for this.

                                    However, it produces non-persistent classes for views because views do not have primary keys. In order to use this class to retrieve data, you should set its Persistent property to True and manually declare a key. Refer to the How to map a persistent object to a view (A1383) article to learn how to choose or create a key property for a view. To declare a key for a class, select the field and set its Key property to True.

                                    Q: I wish to use the wizard to generate a model but continue development in code only. What should I do?
                                    A: The designer updates the source code files when you save the model. If you are not going to use the designer after class generation, you can freely edit generated classes. To avoid losing your source code customizations by accident, you can delete the model files (*.xpo and *.xpo.diagram).

                                    Q: Why are certain tables and columns grayed in the wizard and I cannot import them?
                                    A: Tables and columns are grayed when they don't meet XPO requirements. For example, a table has no primary key declared or a column type is not supported. To find out exactly why an item is grayed, hover the mouse cursor over it - the cause of disabling will be shown in the tooltip.

                                    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 navigate to required classes using the visual diagram. Can I search and navigate by class name?
                                    A: Sure, you can do this using the tree under the Data Model | Classes node in the ORMDataModel tab (usually appears near the Solution Explorer tab). 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 (powered by the Visual Studio Visualization and Modeling SDK). Refer to the video for more information.

                                    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 visual diagram of our designer is powered by 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. You can check if this component is installed by searching the Microsoft.VisualStudio.Modeling.Sdk.1X.0.dll assembly in the IDE installation folder, for instance: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\PrivateAssemblies.

                                    If this does not help, check out if the DevExpress ORM Data Model Wizard extension is NOT disabled in the Manage Extensions menu.

                                    See also:
                                    Data Model Designer
                                    Data Model Wizard

                                    #Could not load type npgsql.npgsqlConnection

                                0 Solutions

                                Creation Date Importance Sort by