Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I built up a class called Project:
C#
[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:

C#
public class TodoToolContext : DbContext
    {
        // Tasks:
        public DbSet<TaskProfile> TaskProfiles { get; set; }
        // Projects:
        public DbSet<ProjectProfile> ProjectProfiles { get; set; }
    }


and the call:

C#
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
Posted

1 solution

Hi , to do so you should use LINQ, you can not assign this directly
 
Share this answer
 
v2
Comments
je-wo 9-Aug-13 8:40am    
You mean LINQ?
vyas_pratik20 9-Aug-13 8:44am    
ya sorry LINQ
je-wo 11-Aug-13 13:47pm    
Thank you very much, that helped a lot. So I do not need to invest any more time in research.

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