Sdílet prostřednictvím


How to: Create and Modify Complex Types (Entity Data Model Tools)

This topic describes how to create and modify complex types with the ADO.NET Entity Data Model Designer (Entity Designer). For information about using complex types, see Complex Type Objects (Entity Framework).

You can create and modify complex types in the Model Browser window of the Entity Designer. The following procedures assume that you have an .edmx file open in the Entity Designer and that the Model Browser window is visible.

Creating a Complex Type

You can create a complex type in any of the ways listed below.

To create a complex type

  1. In the Model Browser, right-click the Complex Types folder, point to Add, and then click Complex Type.

    A new complex type is added to the folder with a default name (for information about providing a different name, see "Renaming a Complex Type" below).

  2. Add properties to the complex type.

    For more information, see "Adding Properties to a Complex Type" below.

    - OR -

  3. In the Model Browser, select the Complex Types folder and press the Insert key on your keyboard.

    A new complex type is added to the folder with a default name.

  4. Add properties to the complex type.

    - OR -

  5. On the Entity Designer surface, select one or more properties (excluding navigation properties) of an entity, then right-click and select Refactor into New Complex Type.

    A new complex type with the selected properties is added to the Model Browser. The complex type is given a default name.

    A complex property of the newly created type replaces the selected properties. All property mappings are preserved.

    - OR -

  6. Add a function import to your conceptual model and click Create New Complex Type in the Function Import dialog box. For more information, see How to: Import a Stored Procedure (Entity Data Model Tools).

Renaming a Complex Type

When you rename a complex type, all references to the type are updated throughout the project.

You can rename a complex type in any of the ways listed below.

To rename a complex type

  • Slowly double-click a complex type in the Model Browser.

    The name will be selected and in edit mode.

    - OR -

  • Right-click a complex type in the Model Browser and select Rename.

    The name will be selected and in edit mode.

    - OR -

  • Select a complex type in the Model Browser and press the F2 key.

    The name will be selected and in edit mode.

    - OR -

  • Right-click a complex type in the Model Browser and select Properties. Edit the name in the Properties window.

Adding Properties to a Complex Type

Properties of a complex type can be scalar types or existing complex types. However, complex type properties cannot have circular references. For example, a complex type ContactInfo cannot have a property of complex type ContactInfo.

You can add a property to a complex type in any of the ways listed below.

To add a property to a complex type

  • Right-click a complex type in the Model Browser, point to Add, then point to Scalar Property or Complex Property, then select the desired property type.

    A new property is added to the complex type with a default name.

    - OR -

  • Right-click an entity property on the Entity Designer surface and select Copy, then right-click the complex type in the Model Browser and select Paste.

    - OR -

  • Select a complex type in the Model Browser and then press the Insert key on your keyboard.

    A new scalar property is added the complex type with a default name.

Deleting a Complex Type

When you delete a complex type, the type is deleted from the conceptual model and mappings for all instances of the type are deleted. However, references to the type are not updated. For example, if an entity has a complex type property of type ComplexType1 and ComplexType1 is deleted in the Model Browser, the corresponding entity property is not updated. The model will not validate because it contains an entity that references a deleted complex type. You can update or delete references to deleted complex types by using the Entity Designer.

You can delete a complex type in the following ways:

To delete a complex type

  • Right-click a complex type in the Model Browser and select Delete.

    - OR -

  • Select a complex type in the Model Browser and press the Delete key on your keyboard.

See Also

Tasks

How to: Add a Complex Type Property to an Entity (Entity Data Model Tools)
How to: Map Complex Type Properties to Table Columns (Entity Data Model Tools)
How to: Map a Function Import to a Complex Type (Entity Data Model Tools)

Other Resources

Modeling Tasks with the Entity Data Model Tools