【发布时间】:2012-08-01 00:35:22
【问题描述】:
我想知道在制作模型时处理关系默认值的最佳方法是什么。 (特别是 EF4)
例如,我的组织有一个默认联系人,我想知道哪个是最好的方法。我有这两个选项(或任何其他人建议如果更好)
使用关系:
public class Contact
{
public int Id { get; set; }
public string FirstName { get; set; }
}
public class Organization
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Contact> Contacts { get; set; }
//Use a relationship for the default contact?
public Contact DefaultContact { get; set; }
}
使用价值:
public class Contact
{
public int Id { get; set; }
public string FirstName { get; set; }
//Use value?
public boolean IsDefault { get; set; }
}
public class Organization
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Contact> Contacts { get; set; }
}
【问题讨论】:
-
为了降低复杂性,我会选择选项 2。并不是第一个选项过于复杂,但拥有 bool 属性似乎比自定义类型属性更直接且更易于管理
-
这个问题首先远远超出了 EF 4 模型甚至 OR/M,因为它对任何 OR/M 甚至数据库级别都有影响。考虑到这一点,我会考虑编辑这个问题,它将覆盖更广泛的受众。
-
我同意,但由于具体技术是 EF,我会保留这些标签,以了解其他人在使用相同工具之前如何解决这种情况。 Tnx 马克。
标签: asp.net visual-studio-2010 oop orm entity-framework-4