Normalized class design and code first
Posted
by
dc7a9163d9
on Stack Overflow
See other posts from Stack Overflow
or by dc7a9163d9
Published on 2013-10-28T03:50:18Z
Indexed on
2013/10/28
3:53 UTC
Read the original article
Hit count: 122
There are the following two classes.
public class Employee
{
int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Street { get; set; }
public string Street2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
public class Company
{
int CompanyId { get; set; }
public string Name { get; set; }
public string Street { get; set; }
public string Street2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
In a DDD seminar, the speaker said the better design should be,
class PersonName
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
class Address
{
public string Street { get; set; }
public string Street2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
public class Employee
{
int EmployeeId { get; set; }
public PersonName Name { get; set; }
[ForeignKey("EmployerAddress")]
public int EmployerAddressId { get; set; }
public virtual Address EmployerAddress { get; set; }
}
public class Company
{
int CompanyId { get; set; }
public string Name { get; set; }
[ForeignKey("CompanyAddress")]
public int CompanyAddressId { get; set; }
public virtual Address CompanyAddress { get; set; }
}
Is it the optimized design? How the code first generate the PersonName
table and link it to Employee?
© Stack Overflow or respective owner