Ok, the title is not quire accurate, I’m not aware of any way to accomplish truly immutable types for Entity Framework.
However, this is a quite nice attempt IMO:
public class Address
{
//Private setters to avoid external changes
public string StreetName { get;private set; }
public string City { get; private set; }
public string ZipCode { get; private set; }
//Provide a default ctor for EF4
[Obsolete("For EF4 Only",true)]
public Address() {}
//Force values to be set via ctor.
public Address(string streetName, string city, string zipCode)
{
StreetName = streetName;
City = city;
ZipCode = zipCode;
}
...equality overrides and such...
}
This works very well with Entity Framework 4 and I think it is a fair compromise.
//Roger

Hello,
How can you map value objects in EF4 ?
Hi there check out my article and see if it looks fine for you: http://christianarg.wordpress.com/2010/09/10/c-net-immutable-properties-for-entity-framework-serializable-classes-etc/