Let’s say in my EF6 project [Database-first approach] I have a complex type called Address
[just to clarify my complex type does not have any identity and is only a merge of aggregation of standalone data and it is not even responsible for its own persistence]
Currently I have all the fields associated with the address as direct properties for the constituent parts of the address and have the following automatically-generated definition for Person class:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Nullable<int> Easting { get; set; }
public Nullable<int> Northing { get; set; }
public string Building { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public string StreetName { get; set; }
public string StreetNumber { get; set; }
public string Town { get; set; }
public string Unit { get; set; }
public string Village { get; set; }
public int CountryId { get; set; }
}
Ideally I would like to have something like the following [every time I update model from database]:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public Nullable<int> Easting { get; set; }
public Nullable<int> Northing { get; set; }
public string Building { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
public string StreetName { get; set; }
public string StreetNumber { get; set; }
public string Town { get; set; }
public string Unit { get; set; }
public string Village { get; set; }
public int CountryId { get; set; }
}
How would I be able to have all address related fields as an aggregated field called Address when I update my model from the database (SQL Server 2012)?
As far as I know the only way forward is modifying T4 template. If your only suggested solution is T4 template alternation could you please show me some sample projects taking similar strategies or provide your own version.