Creating a Complex Type

Complex types are data types with internal structure but without Key properties. They are represented as light-green shapes on the diagram. They define a data structure composed of scalar or enum properties or other complex types.

 

ExpandedToggleIcon        General Features of Complex Types

The main properties of complex types are:

Complex types do not have identities (or keys) and therefore cannot exist independently. They can only exist as properties of entity types or other complex types or as the result type of a method.
A complex type property cannot have a null value, though the scalar properties of a complex type may each be set to null.
Complex type properties are available for modifying. Its constructor has no parameters.

Complex types enable scalar properties to be organized within entities. The fields of these objects are mapped to the same record in the database table with the fields of the parent entity.

You can use complex types for a more precise presentation of the denormalized table structure and for the specific types returned from stored procedures and functions.

There are several ways to create a complex type. They are described below.

 

ExpandedToggleIcon        Creating Complex Types from Existing Objects

Creating a Complex Type from an Entity

To create a complex type from an existing entity, select the properties from this entity and create a complex type based on them. For example, you have the Company entity and want to create a complex type describing Address. For that purpose, perform the following steps:

1.Click the Address property in the Company class, and then click the Country property while holding down the SHIFT key.

Images_company-class

2.Drag the selected properties out of the Company class and place them onto the empty diagram space.
3.In the displayed Model Refactoring dialog box, select the New complex type radio-button and then click OK.
4.The new complex type has been created. Its properties can be edited in the Type Editor dialog. To display Type Editor, double-click the complex type or select Edit from the complex type shortcut menu.

Images_typeeditor

Creating a Complex Type from an Entity Using Model Refactoring

1.Select the classes with a set of the common properties.
2.Right-click the selected properties and in the displayed context menu click the Model Refactoring... menu item.
3.In the displayed Model Refactoring dialog box, click the New complex type, if necessary, specify the name of the new complex type and then click OK.
4.Select check boxes for the common properties to migrate to the new complex type.
5.The new complex type that contains the common set of properties (that had the same names and types in the selected classes) has been created. Its properties can be edited in the Type Editor dialog. To display Type Editor, double-click the complex type or select Edit from the complex type shortcut menu.

note Note

If you create a complex type for several classes with a similar subset of properties using Model Refactoring, and these properties have different facets in different classes, facets from the class that was selected first are taken as a facets for the properties of a new complex type.

 

ExpandedToggleIcon        Creating a New Complex Type

To create a new complex type perform the following steps:

1.Right-click the Complex Types node in the Model Explorer and select New Complex Type from the shortcut menu.
2.The new complex type has been added to the model. Double-click it to edit the set of properties.

note Note

To add a property to the newly-added complex type use one of the following options. Select the complex type and press the INSERT key - this will add a new property, or press ALT+P - this will call the Property Editor dialog allowing you to configure the new property immediately. When working with the Type Editor dialog, right-click in the Properties area of the dialog and select the Add Property command from the shortcut menu, or press the INSERT key. To edit a property, right-click it and select the Edit Property command from the shortcut menu or press ENTER to display the Property Editor dialog. To remove a property from the Properties area of the Type Editor dialog, right-click the property and select the Delete Property from the shortcut menu or press the DELETE key.

note Note

A complex type created in this way is not mapped initially which is indicated in the Error List window with the corresponding warning message: The complex type '<type name>' is not used by any object within the model. For detailed information on complex type mapping, refer to Component Mapping.

note Note

There are several ways to create a new complex type besides the described one:

Right-click the model name node in the Model Explorer and in the displayed context menu select Add, then select New Complex Type;
Click on an empty diagram space, in the context menu select Add, then select New Complex Type;
In the menu bar click the Model menu and then click New Complex Type;
In the main toolbar click the New Complex Type button;
In the Model Explorer toolbar click the New Complex Type button;
Or just use the hot keys ALT+X to create a new complex type.

 

ExpandedToggleIcon        Deleting a Complex Type

To delete a complex type use one of the following options:

in case you want to delete the complex type from the diagram area only, select it in the diagram area and press SHIFT+DELETE;
right-click the required complex type on the diagram area or in the Model Explorer, and select Delete in the context menu or select the required complex type and press the DELETE key.

Entity Developer will then ask you whether you want to delete the object from the model too.

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.