Complex Types

Introduction
Creating Complex Type from the Existing Entity
Creating New Complex Type
Returning Complex Type from Method

 

ExpandedToggleIcon        Introduction

Complex types are data types with internal structures but without Key properties. They are represented as light-green shapes on the diagram.

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 as the fields of the parent entity.

When you work with objects that represent complex types, be aware of the following points:

Complex type can be implemented without any parents or interfaces (only in POCO model).
Properties of the complex type have to be marked as attributes.
Complex type properties are available for modifying. Its constructor has no parameters.
Complex types cannot participate in associations because complex type cannot have an entity key.
You can use complex types for more precise presentation of the denormalized table structure and for the specific types returning from stored procedures and functions.

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

 

ExpandedToggleIcon        Creating Complex Type from the Existing Entity

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

Images_company-class

1.Click the Address property in the Company class, then press SHIFT and click the Country property holding the SHIFT key.
2.Drag the selected properties out of the Company class and drop them on the empty diagram space.
3.In the displayed Model Refactoring dialog box, click New complex type and then click OK.
4.The new complex type is created. You can edit its properties using Type Editor. To load Type Editor, double-click the complex type or select Edit from the complex type popup menu.

Images_TypeEditorLC

 

 

ExpandedToggleIcon        Creating 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 is 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.

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        Returning Complex Type from Method

To return a complex type from the method, do the following:

1.Include the functions or stored procedures to the model during its creation. You can use stored procedures and functions which return recordset and all of their input parameters can be null.

 

Images_complextype_methodeditor

2.A new complex type is created automatically. You can edit it as described in the previous chapter.

 

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.