using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel; using DataAnnotationsExtensions; using System.ComponentModel.DataAnnotations.Schema; using System.Collections.Generic; namespace CardNumbers.Objects { [ComplexType] public class PhoneInfo { [DataType(DataType.PhoneNumber)] [StringLength(10)] [DisplayName("Phone")] public virtual string Phone { get; set; } [StringLength(5)] [DisplayName("Ext")] public virtual string Ext { get; set; } public bool HasValue { get { return (Phone != null || Ext != null); } } } [ComplexType] public class ContactDetail { //Constructor public ContactDetail() { phoneInfo = new PhoneInfo(); } [StringLength(100)] [DisplayName("Contact Name")] [DisplayFormat(NullDisplayText = "")] public virtual string Contact { get; set; } [Email] [StringLength(100)] [DisplayName("Email")] public virtual string Email { get; set; } public virtual PhoneInfo phoneInfo { get; set; } public bool HasValue { get { return (Contact != null || Email != null || phoneInfo.HasValue); } } } public class Client { [Key] [Column("ClientId",TypeName = "int")] public virtual int Id { get; set; } [Required] [DisplayName("Client No")] [Column("client_no", TypeName = "smallint")] public virtual Int16 Number { get; set; } [Required] [Column("client_name", TypeName = "varchar")] [DisplayName("Client Name")] [MaxLength(30, ErrorMessage = "Client Name should not be longer than 30 characters" )] [MinLength(3, ErrorMessage = "Client Name is too short")] public virtual string Name { get; set; } [StringLength(100)] [DisplayName("First Contact")] [DisplayFormat(NullDisplayText = "")] [Column("Contact1",TypeName = "varchar")] public virtual string Contact1 { get; set; } [Email] [StringLength(100)] [Column("c1_email", TypeName = "varchar")] public virtual string Email1 { get; set; } [DataType(DataType.PhoneNumber)] [Column("C1_Phone", TypeName = "varchar")] [StringLength(10)] [DisplayName("Phone")] public virtual string Phone1 { get; set; } [StringLength(5)] [Column("C1_Ext", TypeName = "varchar")] [DisplayName("Ext")] public virtual string Ext1 { get; set; } [StringLength(100)] [DisplayName("Second Contact")] [Column("Contact2", TypeName = "varchar")] public virtual string Contact2 { get; set; } [Email] [StringLength(100)] [Column("C2_Email", TypeName = "varchar")] public virtual string Email2 { get; set; } [DataType(DataType.PhoneNumber)] [StringLength(10)] [DisplayName("Phone")] [Column("C2_Phone", TypeName = "varchar")] public virtual string Phone2 { get; set; } [StringLength(5)] [DisplayName("Ext")] [Column("C2_Ext",TypeName = "varchar")] public virtual string Ext2 { get; set; } [DataType(DataType.MultilineText)] public virtual string Address { get; set; } [ForeignKey("EnteredByOperator")] public string EnteredBy { get; set; } [InverseProperty("ClientsEnteredBy")] public virtual Operator EnteredByOperator { get; set; } [ForeignKey("ModifiedByOperator")] public string ModifiedBy { get; set; } [InverseProperty("ClientsUpdatedBy")] public virtual Operator ModifiedByOperator { get; set; } [DataType(DataType.DateTime)] [DisplayName("Created on")] public DateTime EnteredOn { get; set; } [DataType(DataType.DateTime)] [DisplayName("Modified on")] public DateTime? ModifiedOn { get; set; } public virtual ICollection<ClientOrder> ClientOrders { get; set; } public virtual ICollection<Reorder> Reorders { get; set; } } }Do you see what should I do to make contact1, email1, phone1 and Ext1 to map to the ContactDetail1 if I introduce this class?
public class EntityMappingContext : DbContext { public DbSet<User> Users { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new UserConfiguration()); } } class UserConfiguration : EntityTypeConfiguration<User> { public UserConfiguration() { Property(u => u.DeliveryAddress.Street).HasColumnName("DeliveryAddress_Street"); Property(u => u.DeliveryAddress.City).HasColumnName("DeliveryAddress_City"); Property(u => u.DeliveryAddress.PostalCode).HasColumnName("DeliveryAddress_PostalCode"); Property(u => u.HomeAddress.Street).HasColumnName("HomeAddress_Street"); Property(u => u.HomeAddress.City).HasColumnName("HomeAddress_City"); Property(u => u.HomeAddress.PostalCode).HasColumnName("HomeAddress_PostalCode"); } }So, is it what I will use if instead of my current code I'll go with public ContactDetail Contact1 {get;set;}