I have some POCO classes which can generally divided into two groups, for example:
public class Student
{
public Student()
{
this.Courses = new List<Course>();
this.Clubs = new List<Club>();
}
public int Id { get; set; }
public virtual ICollection<Course> Courses { get; set; }
public virtual ICollection<Club> Clubs { get; set; }
}
and corresponding Course and Club classes, and they all have their own relationships to other classes.
The problem is, those two groups are big, they both contains a lot of classes, and each of them is a working unit, like student courses management unit which will provide functions for anything related to course; and club management unit which will provide functions. So I am not planning to put them together into one DbContext.
There are some requirements that will need to get a student from club then retrieve its course information. What I am doing now, is do another query in course unit by using the student Id I got from club unit. Which works fine but I hopping to make it simpler, like
foreach(var student in club.Students){
ClubContext.Detach(student);
CourseContext.Attach(student);
foreach(var c in student.Courses){
...
}
}
but I got some exception like this:
There is already a generated proxy type for the object layer type 'POCOTest.Models.Student'. This occurs when the same object layer type is mapped by two or more different models in an AppDomain.
Is this possible? and if so, how? Thanks~