Appendix B. Data-Binding with Complex Types

In Chapter 14, you learned how to create complex types and use them to encapsulate properties in an entity. As an example, you temporarily encapsulated a number of properties (Street1, Street2, City, and StateProvince) of the Address entity into a complex type called Mail, as shown in Figure B-1.

The Address entity with its Mail complex property

Figure B-1. The Address entity with its Mail complex property

The chapter looked briefly at data binding when an entity contains a complex type. Complex types may not behave the way you would expect them to in data binding. Therefore, this appendix will take a look at a number of specific data-binding scenarios that you may encounter in your applications.

Using Complex Types with ASP.NET EntityDataSource

When you use complex types with the EntityDataSource, the EntityDataSource “flattens” the properties within the complex type to make them easily accessible. When configuring the EntityDataSource, you will see the type, but not the properties. However, when binding controls to the data source, the properties of the complex type appear as though they were simply properties of the parent type. You can see this in the screenshot in Figure B-2.

The complex type properties automatically flattened

Figure B-2. The complex type properties automatically flattened

This flattening of the properties is a feature of the ...

Get Programming Entity Framework, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.