Reputation: 470
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?
Upvotes: 0
Views: 53
Reputation: 1213
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 .
Upvotes: 1