KB Article KA18957
Visible to All Users

How do I declare an image property in the ORM Data Model Designer

Description:
By default, the Column Type editor for a field lists only simple .NET types and also designable persistent types from your ORM data model.
This article describes how to declare a field of a complex or external type in the ORM Data Model designer, which is not listed in the editor by default. In particular, here it is demonstrated how to declare a property of the System.Drawing.Image type from the external System.Drawing assembly.

Answer:
To accomplish this task, it is important to know how image properties are usually defined in XPO.
Check out the following XPO articles for more information and example code on this:
   Approach #1 (via the System.Drawing.Image type),
   Approach #2 (via the System.Byte[] type).
Then, proceed to the designer and execute the following steps:
1. In Solution Explorer, double-click on the YourORMDataModelName.xpo item to invoke the designer:

2. Select the ORMDataModel tab, which should usually appear at the left of Solution Explorer, and right-click the root Data Model item

3. Select Add New External Type. A new item will be added to the External Types node.
4. In the Properties window, focus the new External Type item and specify its properties as follows: Name = Image, Namespace = System.Drawing

Here you may also check your project references and make sure the System.Drawing assembly is added into the project.
5. Go back to the persistent property item in the designer and select the newly added type in the Column Type combo box:

6. In the Properties window, set Value Converter = DevExpress.Xpo.Metadata.ImageValueConverter:

As a result, the following property will be auto-generated in the *.designer.cs file:

C#
System.Drawing.Image fPhoto; [DevExpress.Xpo.ValueConverter(typeof(DevExpress.Xpo.Metadata.ImageValueConverter))] public System.Drawing.Image Photo { get { return fPhoto; } set { SetPropertyValue<System.Drawing.Image>("Photo", ref fPhoto, value); } }

If you want to have a byte array property instead of the System.Drawing.Image one, do not declare an external type, just choose ByteArray in the Column Type editor, and set the ValueConverter property (step #6). Of course, you can specify additional options in the designer depending on your exact business requirements.

IMPORTANT NOTE
If you are developing an XAF application, bear in mind that XAF uses the DevExpress.Persistent.Base > ImageEditor attribute to distinguish image properties from other byte array properties. You can learn more about this from Concepts > Business Model Design > Data Types Supported by built-in Editors > BLOB Image Properties > BLOB Image Properties in XPO
Refer to the "Q: How can I decorate my classes and properties with attributes?"  section of the ORM Data Model Designer and Wizard FAQ article to learn more about adding this attribute using the visual designer.

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.