Complex type inside Database-first model of a DDD project

.net c# ef-database-first entity-framework entity-framework-6

Question

Let's imagine I have a complex type called "A" in my EF6 project (database-first approach).Address [so to be clear, my complex type has no identity, is merely an aggregate of standalone data, and is not even in charge of maintaining its own persistence]

I currently have the following automatically produced definition for the Person class and all the fields connected to the address as direct properties for the address's component parts:

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; }
}

I would prefer to have something along these lines [each time I update the model from the 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; }
}

When I update my model from the database (SQL Server 2012), how can I have all address-related fields as one aggregated field called Address?

The only option, as far as I'm aware, is to change the T4 template. If you have any other suggestions except changing the T4 template, do give them or show me some examples of projects that used them.

1
2
12/13/2016 5:13:51 PM

Popular Answer

ZZZ_tmp
0
10/26/2014 2:22:52 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow