0

I want to Map the relationships between my entities like this:

public partial class Profile  {
    [Key]
    public int ProfileId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string MiddleName { get; set; }
    public string Gender { get; set; }
    public string DateOfBirth { get; set; }
    public int Age { get; set; }
    public string CivilStatus { get; set; }
    public string Email { get; set; }
    public string Telephone { get; set; }
    public string Mobile { get; set; }
    public string City { get; set; }
    public string District { get; set; }
    public string Province { get; set; }
    public string Region { get; set; }
    public int Zip { get; set; }


    public virtual Application Application { get; set; }
    public virtual Education Education { get; set; }
    public virtual Identification Identification { get; set; }
    public virtual Job Job { get; set; }
    public virtual Resume Resume { get; set; }
    }

public partial class Resume {
    public int ResumeId { get; set; }
    public int ProfileId { get; set; }
    public string ResumeFile { get; set; }

    public virtual Profile Profile { get; set; }
  }

public partial class Job
{


    public int JobId { get; set; }
    public int ProfileId { get; set; }
    public string PreviousCompany { get; set; }
    public string InclusiveDate { get; set; }
    public string Position { get; set; }

    public virtual Profile Profile { get; set; }
}

public partial class Education
{


    public int EducationId { get; set; }
    public int ProfileId { get; set; }
    public string School { get; set; }
    public string EducationLevel { get; set; }
    public string YearGraduated { get; set; }
    public string Degree { get; set; }

    public virtual Profile Profile { get; set; }
}

I wanted to make A 1 to 1 relationship from Profile class to other classes using just the Profile Id as the foreign instead of having all the id's of the related Classes. How would I do that using fluent Api?? I also need to have Resume => requires one Profile... How can I do that or is it possible??.

ECie
  • 1,265
  • 4
  • 21
  • 50

1 Answers1

1

If you want map everything in one table you can add annotation [Table("Profile")] to each class and remove from them diferent Ids. This operation is called "Table spliting" I can recomend you this video: http://www.youtube.com/watch?v=l9QXArMPyHc&index=13&list=PL6n9fhu94yhUPBSX-E2aJCnCR3-_6zBZx to improve your understanding of the question.

Andrey
  • 160
  • 1
  • 9
  • I was looking for that. Thanks – ECie Sep 04 '15 at 08:36
  • In video discussed a slightly different way to do this operation but with the same effect. – Andrey Sep 04 '15 at 08:38
  • yeah.. great. i don't even know that Fluent Api can do that. REALLY great approach – ECie Sep 04 '15 at 08:42
  • how would my Primary Key on the small tables look like?? does that means i need to enable cascade on Delete and Disable the databaseGenerated option to none?? the small entities will really depend on that Pointer entity right??? – ECie Sep 04 '15 at 09:07
  • you can use ProfileId. you don't need cascade delete, update and so on because all your data are in one table. You access your small entity thought navigation properties in Profile. – Andrey Sep 04 '15 at 10:30
  • thanks a lot. ive learned another thing. I think i will keep it as one to one relationship.. I want to have that table splitting but in my requirements i need to separate the table so that another program will just pick up just that table so we can depend on the database – ECie Sep 07 '15 at 01:50