I built up a class called Project:
[Table("Projects")]
public class ProjectProfile
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<User> HeadOf { get; set; }
public virtual ICollection<User> Engineer{ get; set; }
}
Writing is not a problem, I built the obejct, add a HeadOf and Engineer collection and write it into the database. But when I read the whole thing by the class:
public class TodoToolContext : DbContext
{
public DbSet<TaskProfile> TaskProfiles { get; set; }
public DbSet<ProjectProfile> ProjectProfiles { get; set; }
}
and the call:
TodoToolContext db = new TodoToolContext();
List<ProjectProfile>list = db.ProjectProfiles.toList();
I get a list of projects (which is right), all the native datatypes in it are filled with data (ID, Name, Description) which is also right, but the ICollections are empty, so the connection between the project and the engineers and headofs is lost.
My question is now, how to read such "complex" objects from the database? Is it necessary to read back each "Project", search for the right "Engineers" and "HeadOfs" by myself via LINQ and make the connection by myself again?
Isn`t there an easier way?
Best
J