I found these entities in one of Microsoft tutorials:
public class Enrollment
{
public int Id{ get; set; }
public int StudentId { get; set; }
public Student Student { get; set; }
}
public class Student
{
public int Id { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
}
Do I really need to define StudentId
property?
How the case will differ in case of different types of relationshipts? for example one-one
and one-many
?
In this link http://www.learnentityframeworkcore.com/relationships we can see that in One-Many and Many-Many, they did not define the Id foreign key property, but in One-One, they did. Why is that?
I found a partial answer for my question in this page:
http://www.learnentityframeworkcore.com/conventions
Foreign Key Shadow Properties:
If you choose not to explicitly include a foreign key property in the dependant end of the relationship, EF Core will create a shadow property using the pattern Id.
But I still do not know if this is the case in all types of relationships.
I hope that helps some one.
Ok now I found exactly what I wanted to know and understand, please take a look on these links which include the difference conventions of creating the Models (entities):
http://www.learnentityframeworkcore.com/conventions/one-to-many-relationship
http://www.learnentityframeworkcore.com/conventions/one-to-one-relationship
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With