Loading ...

Entity Framework One To Many Relationship

Hello everybody,

today I want to make short post on how to confiugre one to many relationship in Entity Framework 6.

Imagine following: One group can have multiple students. So one to many relationship. For this purpose you can use following convention configuration agreement:

public class Student
{
    public int StudentId { getset; }
    public string StudentName { getset; }
}
 
public class Group
{
    public int GroupId { getset; }
    public string GroupName { getset; }
    public string Department { getset; }
 
    public List<Student> Students { getset; }
}

 

In presented example class group includes navigation property Students. 

Another convention is like this:

public class Student
{
    public int StudentId { getset; }
    public string StudentName { getset; }
 
    public Group CurrentGroup { getset; }
}
 
public class Group
{
    public int GroupId { getset; }
    public string GroupName { getset; }
    public string Department { getset; }
 
    public List<Student> Students { getset; }
}

 

as you can see, difference is that Student instance by itself knows to which Group it belongs. 

If you're working on Acumatica development and need custom solutions tailored to your business, we’re here to help! Whether it’s optimizing data relationships, streamlining workflows, or building custom features, our team can bring your vision to life.

Request a customization today and let’s enhance your Acumatica experience!