How to use complex type objects in Entity Framework 4

This article has been archived. It is offered "as is" and will no longer be updated.
This article describes an All-In-One Code Framework sample that is available for download. This code sample demonstrates how to use complex type, which is one of the new features of Entity Framework 4.0 (EF4). This code sample shows how to add complex type properties to entities, how to map complex type properties to table columns, and how to map a Function Import to a complex type.

Difficulty level

Download information

To download this code sample, click the following link:


Technical overview

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. Because complex types do not have keys, complex type objects cannot be managed by the Entity Framework apart from the parent object.

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.

This sample demonstrates how to add complex Type properties to entities, how to map complex type properties to table columns, and how to map a Function Import to a complex type.

For more information about how to create the sample application and how to deploy the sample application, see the Readme.txt file that is included in the download package.

Technology category

  • ADO.NET Entity Framework


This code sample contains the following programming languages:

LanguageProject Name
Visual C#CSEFComplexType
Visual Basic.NETVBEFComplexType


  • This sample application was created by using Visual Studio 2010.
  • You must attach the database file (EFDemoDB.mdf) that is included in the download package and then modify the connection string in the App.config file according to your database instance and login account.


  • Entity Framework, Complex Type


What is All-In-One Code Framework?

All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site:

How to find more All-In-One Code Framework samples

To find more All-In-One Code Framework samples, you can simply click the following link:

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Article ID: 2127408 - Last Review: 12/12/2015 08:47:38 - Revision: 3.0

Microsoft Visual Studio 2010 Professional, Microsoft Visual Studio 2010 Ultimate

  • kbnosurvey kbarchive KB2127408