I have tried to read the msdn article on complex types. But it does not explain when to use it. Also there is not a comprehensive explanation on the web on complex types and
Consider this ContactDetails
class for example:
public class ContactDetails
{
public string HomePhone { get; set; }
public string MobilePhone { get; set; }
public string FaxNumber { get; set; }
}
By default, EF will treat ContactDetails
as an Entity. That means that if (for example) you're having a Person
class with a navigation-property of ContactDetails
type, EF will map the Person.ContactDetails
relationship to a different table (because Entity is something that is having an identity of its own, hence other entities may refer to it - and that would require a different table in relational terms).
By denoting ContactDetails
as a Complex Type instead, EF will no longer treat it as an entity that requires a relationship and instead map it to the same table of the parent (containing) entity (Person
in my example), effectively making it a Value Object.