combination of two field must be unique in Entity Framework code first
approach. how it would?
I have two class contacts and groups
Combination of FirstName and LastName must be unique and can add multiple
addresses for a single contact. How I can done this in entity framework
code first approach?
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; }
}
No comments:
Post a Comment