0

Am new to fluent API kindly bear with me. I have three entities Student, Address and Course, Student and Address should be 1:1 relationship and Student and Courses should be m:m(many to many).

My question is should i define Courses and Address entities as many to many or should i just access contacts through students if i want to know how many courses are being taken by a particular address(uni-directional association) Below are my fluent api mappings, i have moved the configurations outside.

     public CourseMappings()
                {
                    HasMany<User>(s => s.Student)
                        .WithMany(c => c.Course);
                }

 public AddressMappings()
            {

                HasRequired(c => c.Student)
                .WithRequiredDependent(u => u.Address);
            }


public StudentMapping()
            {

                HasRequired(c => c.Address)
                .WithRequiredPrincipal(u => u.Student);

            }

How do i map courses and address entities using fluent api ,do really i need to or is the association of student & course enough?

Michael Mburu
  • 460
  • 1
  • 4
  • 11
  • 1
    Are u sure the Student-Address has a 1 on 1 relationship? there is a possibility that two students have a same address for example. But, if it is the case, you can query for courses of an address through student and you don't need to define a new relation. – Taher Rahgooy Jul 24 '16 at 19:02

1 Answers1

1

you don't need to map courses and adresse since u can access adresses throught student-courses association . when you Access student you can get adresses so what u have done is ok .

MedAmine.Rihane
  • 1,193
  • 10
  • 17