Creating a struct object or complex type

Complex types and struct objects are data types with internal structure but no 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.

Differences between complex types and struct objects

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

Code Generation:

  • Struct objects are generated as structures (with the struct keyword) in code.
  • Complex types are generated as normal classes in code.

Usage:

  • Only struct objects 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 types can be used as a type of the result of a method that calls a stored procedure or function returning one or more resultsets. Struct objects cannot be used for mapping stored routine results.

In Entity Developer: Both are found in the Complex Types node in the Model Explorer and have no visual differences on the diagram. Both have an Is Struct property that determines whether the type is generated as a struct and how it can be used in the model.

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 be null, 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.

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

You can use complex types for:

  • A more precise presentation of the denormalized table structure.
  • Specific types returned from stored procedures and functions (depending on the Is Struct property value).

Creating struct objects from existing objects

Creating a struct object from an entity

To create a struct object from an existing entity:

1. Click the first property in the entity class (for example, the Address property in the Company class).

2. Hold down SHIFT and click the last property you want to include (for example, the Country property).

Company class with selected properties

3. Drag the selected properties out of the entity class and place them onto the empty diagram space.

4. In the displayed Model Refactoring dialog, select the New complex type radio button and click OK.

5. The new complex type is created. Double-click it to edit properties in the Type Editor dialog.

Type Editor dialog

Creating a struct object from several entities using model refactoring

1. Select the classes with a set of common properties.

2. Right-click the selected properties and in the context menu, click Model Refactoring.

3. In the Model Refactoring dialog, click New complex type and then click OK.

4. The new complex type is created with the common set of properties. Double-click it to edit properties in the Type Editor dialog.

Note

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

Creating a new complex type

To create a new complex type:

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.

3. Select the Is Struct checkbox if this complex type should be used as a type of entity property.

Adding properties to a complex type

To add a property to the newly-added complex type, use one of these options:

  • Select the complex type and press INSERT to add a new property.
  • Press ALT+P to call the Property Editor dialog.
  • In the Type Editor dialog, right-click in the Properties area and select Add Property.
  • Press INSERT in the Type Editor dialog.

To edit a property, right-click it and select Edit Property or press ENTER to display the Property Editor dialog.

To remove a property, right-click it and select Delete Property or press DELETE.

Note

A complex type created in this way is not mapped initially. The Error List window displays a warning: “The complex type <type name> is not used by any object within the model.”

For detailed information, see Complex type mapping.

Alternative ways to create a complex type

Besides the described method, you can create a new complex type by:

  • Right-clicking the model name node in the Model Explorer and selecting Add > New Complex Type.
  • Clicking on an empty diagram space and selecting Add > New Complex Type.
  • Using the Model menu and clicking New Complex Type.
  • Clicking the New Complex Type button in the main toolbar.
  • Clicking the New Complex Type button in the Model Explorer toolbar.
  • Using the keyboard shortcut ALT+X.

Deleting a complex type

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

  • To remove the complex type from the diagram only, select it in the diagram and press Shift+Delete.
  • To delete the complex type from the model, right-click it in the diagram or Model Explorer, then select Delete. Alternatively, select the complex type and press Delete.

Entity Developer asks whether you also want to delete the object from the model.

See also

  • Complex type mapping
  • Working with struct objects and complex types
  • Stored procedure and stored function with resultset
  • Stored procedure with multiple resultsets
  • External struct objects and complex types