Database Reference
In-Depth Information
Figure 2-23. The Agent table with the name and address of the agent
Figure 2-24. The completed model with the name and address components refactored into complex types
Follow these steps to create the model with the Name and Address complex types:
1.
Add a new model to your project by right-clicking your project and selecting Add New
Item. Choose ADO.NET Entity Data Model from the Visual C# Data templates.
2.
Select Generate from database. Click Next.
3.
Use the wizard to select an existing connection to your database or create a new
connection.
4.
From the Choose Your Database Object dialog box, select the Agent table. Leave the
Pluralize and Foreign Key options checked. Click Finish.
5.
Select the FirstName and LastName properties, then right-click and select Refactor Into
Complex Type.
6.
In the Model Browser, rename the new complex type from ComplexType1 to Name.
This changes the name of the type. On the Agent, rename the ComplexTypeProperty
to Name. This changes the name of the property.
7.
We'll create the next complex type from scratch so that you can see an alternative
approach. Right-click on the design surface, and select Add Complex Type.
8.
In the Model Browser, rename the new complex type from ComplexType1 to Address.
9.
Select the AddressLine1, AddressLine2, City, State, and ZIPCode properties in the Agent.
Right-click and select Cut. Paste these properties onto the Address complex type in the
Model Browser.
10.
Right-click the Agent, and select Add Complex Property. Rename the property Address.
11.
Right-click on the new Address property and select Properties. Change its type to Address.
This changes the new property's type to the new Address complex type.
Search WWH ::




Custom Search