Just can't get Entity Framework to pull what I want

Well, I was not very lucky with that. I'm new to the Entity Framework, and have been scared with this little thing ever since.

Here are my tables:

  • Clients (id, clientname)
  • Projects (id, projectname, clientid)
  • Tasks (id, taskname, projectid, statusid)
  • TaskStatuses (id, statusname)

In code, I only work with one project at a time, and here is how I load this project using EF:

thisProject = (from p in dataEntity.projects
                   where p.id == projectID
                   select p).FirstOrDefault();

Then later, when I load tasks:

thisProject.Tasks.Load();

Then I install the DevExpress XtraGrid data source for the downloaded tasks:

taskGridControl.DataSource = thisProject.Tasks;

Up to this point, everything works as expected, and the grid shows all the tasks for the project I downloaded. But I also want to show the "Task Status" field and is stored in another table.

It was very easy with sql connection, but for life I can not understand it.

+3
4

, :

from t in dataEntity.tasks
where t.projectId == projectID
select new TaskInfo
{
    ProjectName = t.project.projectname,
    TaskName = t.taskname,
    StatusName = t.taststatus.statusname
}
+3

, .

, EF 4 - thisProject.Tasks.Load(), .

+1
  • , . , TaskStatus,

    thisProject.Tasks.TasksStatusReference.Load();
    
  • , , , , TaskStatus. : TaskStatus.Status.

0

.

, , ...:) , , .

thisProject = ( p dataEntity.projects.Include( "Tasks.TasksStatuses" )                   p.id == projectID                   p).FirstOrDefault();

( .)

... asp.net? , .

0

Source: https://habr.com/ru/post/1775318/


All Articles