Derek
Derek

Reputation: 8630

Entity Framework 5 Complex Types

I'm all new to EF5 and I'm looking at Complex Types.

I can see why you would use Enum types with your EF Model, but I've also seen examples of where you can create you own complex type whereby your grouping multiple properties in a table under one complex type.

An example would be a table that contained properties such as:-

FirstName

LastName

You can define a complex type called Name, and these two properties can then be referenced like this:-

Name.FirstName

Name.LastName

My question is why would you do this and where do you get the benefits?

As I say, I'm new to EF5, so I'm just trying to get a better understanding of it.

Upvotes: 2

Views: 476

Answers (1)

Tim Long
Tim Long

Reputation: 13778

It's possibly not obvious with just a first name and last name, but consider something more complex like an address. You may need to pass addresses around the system and it is far easier to do if it is in a self-contained object.

You can also re-use complext types. So a good example of that is where you have a customer who has a delivery address and a billing address.

For example: enter image description here

Upvotes: 2

Related Questions