다음을 통해 공유


Complex Type Objects (Entity Framework)

Complex types are non-scalar properties of entity types that enable scalar properties to be organized within entities. Like entities, complex types consist of scalar properties or other complex type properties. A complex type cannot exist without a parent entity or complex type. Because complex types do not have keys, complex type objects cannot be managed by Object Services apart from the parent object. For more information, see Complex Type (EDM).

When the Entity Framework tools generate objects that represent entity types, these objects inherit from EntityObject. Likewise, objects generated for complex types inherit from ComplexObject. Both of these classes inherit from the StructuralObject base class. The scalar properties of complex type objects can be accessed like other scalar properties. For more information, see How to: Create and Execute Object Queries with Complex Types (Entity Framework).

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

  • Complex type properties cannot be null. An InvalidOperationException occurs when SaveChanges is called and a null complex object is encountered. Like scalar properties of entities, scalar properties of complex objects can be null.

  • Complex types cannot inherit from other complex types.

  • When any property is changed anywhere in the object graph of a complex type, the property of the parent type is marked as changed and all properties in the object graph of the complex type are updated when SaveChanges is called.

  • Complex objects that inherit from ComplexObject are instantiated when the complex type property is accessed, and not when the parent object is instantiated.

  • When a custom data class inherits from EntityObject, complex type classes must inherit from ComplexObject.

  • You can use complex types when you implement custom data class interfaces, such as IEntityWithKey. However, the recommended practice for using complex types with custom data classes is to inherit from both EntityObject and ComplexObject. For more information, see Customizing Objects (Entity Framework).

See Also

Other Resources

Working with Objects (Entity Framework)