In my final ASP.NET assignment, I am instructed to use a code first approach and add the following properties and Model(s) to represent the described changes.
1) A Person 'has a' Address object (This class was given, but I modified adding properties)
2) An Address object has a single property of type string for Email. (I created this class)
namespace ContosoUniversity.Models
{
public class Address
{
[Required]
[RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z] {2,4}")]
public string Email { get; set; }
[Required]
[Compare("Email")]
public string EmailConfirm { get; set; }
}
}
but now I am not sure what he means in the first instruction. I have researched composition, inheritance, and abstract classes but still don't know what I am suppose to do?
How am I suppose to create an Address object in the person class? What does that actually mean? Here is the Person class:
namespace ContosoUniversity.Models
{
public abstract class Person
{
public int ID { get; set; }
[Required]
[StringLength(50)]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required]
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
[Column("FirstName")]
[Display(Name = "First Name")]
public string FirstMidName { get; set; }
[Display(Name = "Full Name")]
public string FullName
{
get
{
return LastName + ", " + FirstMidName;
}
}
}
}