Creating a Struct Object or Complex Type

Complex types and struct objects 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 struct objects.

 

ExpandedToggleIcon        Differences between Complex Types and Struct Objects

While Entity Developer works with complex types and struct objects in a similar way, there is a certain differences between them in code generation and how Telerik Data Access allows using them.

Struct objects are generated as structures, not classes, in code (with the struct keyword). Complex type are generated as normal classes in code.

Only struct object can be used as a type of entity properties and properties of other struct objects. Complex types cannot be used as types of properties.

Only complex type can be used as a type of the result of a method, that calls a stored procedure or function, returning one or more resultset. Struct object cannot be used for mapping stored routine result.

Entity Developer works with complex types and struct objects in mostly the same way, and in Entity Developer terms both of these categories can be referred as "complex types". They have the Is Struct property, that can be set in the Properties window or in the complex type editor, and this property determines whether this is a struct object or not and how it can be used in the model. In the Model Explorer window, both struct objects and non-struct complex types can be found in the Complex Types node, and they have no visual differences on the diagram.

 

ExpandedToggleIcon        General Features of Complex Types

The main properties of complex types are:

Complex types do not have identities (or keys).
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 that are struct objects 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, depending on the Is Struct property value.

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

 

ExpandedToggleIcon        Creating Struct Objects from Existing Objects

Creating a Struct Object from an Entity

To create a struct object 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-TDA

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_typeeditorTDA

Creating a Struct Object from Several Entities 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 and then click OK.
4.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.
3.Select the Is Struct check box if this complex type should be used as a type of entity property.

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 Complex Type 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.