我有两个班级联系人和组结合FirstName和LastName必须是唯一的,可以为单个联系人添加多个地址。如何在实体框架代码优先方法中做到这一点?public class Contacts{ [Key] public int ContactID { get; set; } [ForeignKey("Group")] public int GroupID { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Required] public string Address { get; set; } [Required] public string Number { get; set; } [Required] [EmailAddress] public string EmailId { get; set; } [DataType(DataType.Date)] public DateTime CreateDate { get; set; } public DateTime? ModifiedDate { get; set; } public virtual Groups Group { get; set; }}public class Groups{ [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int GroupID { get; set; } [Required] public string GroupName { get; set; } [Required] public string GroupDiscription { get; set; } public DateTime CreateDate { get; set; } public DateTime ModifiedDate { get; set; }}
2 回答
- 2 回答
- 0 关注
- 611 浏览
添加回答
举报
0/150
提交
取消