什么是最佳实践?属性还是实体?
what is best practice? An attribute or an Entity?
我正在尝试建立一个人员目录数据库,其中人员有许多实体,例如地址、Phone,以及电子邮件和便笺。
但我 want/try 将 'Email' 和 'Notes' 实现为 'Person' class 的属性,而不是单独的实体。
如果能帮助我理解如何使用属性实现这一点,我将不胜感激?
这两个选项中哪一个是更好的做法?
我必须补充一点,一个人 should/could 有很多电子邮件地址和笔记。
这是我的人class:
public class Person
{
public Person()
{
this.PrimaryAddress = new Address();
this.AlternativeAddresses = new List<AlternativeAddress>();
this.TelefonNumbers = new List<Telefon>();
}
public int PersonID { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Notes { get; set; }
public virtual Address PrimaryAddress { get; set; }
public virtual List<AlternativeAddress> AlternativeAddresses { get; set; }
public virtual List<Telefon> TelefonNumbers { get; set; }
}
使用与您在
public virtual List<AlternativeAddress> AlternativeAddresses { get; set; }
与
public virtual List<string> EmailAdresses { get; set; }
要么
public virtual List<EmailEntity> EmailAdresses { get; set; }
两者都很好。只看你的喜好和操作类型,以后再做。
我正在尝试建立一个人员目录数据库,其中人员有许多实体,例如地址、Phone,以及电子邮件和便笺。 但我 want/try 将 'Email' 和 'Notes' 实现为 'Person' class 的属性,而不是单独的实体。
如果能帮助我理解如何使用属性实现这一点,我将不胜感激? 这两个选项中哪一个是更好的做法?
我必须补充一点,一个人 should/could 有很多电子邮件地址和笔记。
这是我的人class:
public class Person
{
public Person()
{
this.PrimaryAddress = new Address();
this.AlternativeAddresses = new List<AlternativeAddress>();
this.TelefonNumbers = new List<Telefon>();
}
public int PersonID { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Notes { get; set; }
public virtual Address PrimaryAddress { get; set; }
public virtual List<AlternativeAddress> AlternativeAddresses { get; set; }
public virtual List<Telefon> TelefonNumbers { get; set; }
}
使用与您在
public virtual List<AlternativeAddress> AlternativeAddresses { get; set; }
与
public virtual List<string> EmailAdresses { get; set; }
要么
public virtual List<EmailEntity> EmailAdresses { get; set; }
两者都很好。只看你的喜好和操作类型,以后再做。