Click here to Skip to main content
15,065,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I just started with EF Code First. And I have a question about this. What is the advantage of defining relationships through the Fluent API?

When I create the database from my poco's (or entities) I already have one-to-many and/or many-to-many relationships between my tables.

For ex:

C#
public class School
    {
        public School()
        {
            Students = new List<Student>();
        }

        public Guid Id { get; set; }
        public string Name { get; set; }
        public List<Student> Student{ get; set; }
    }


public class Student
    {
        public Guid Id { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public Guid SchoolId{ get; set; }
        public School School{ get; set; }
    }


This creates already a relationship between Students and School. Does defining a relationship through the Fluent API gives advantages? Or not?

Thanks in advance!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900