편집을 반환 :이 질문은 지금 현재 내가 아주 새로운 오전 LINQ를 사용하여 여러 테이블에서 여러 컬럼의 간단한 선택을하려고LINQ 쿼리는 너무 많은 결과를
를 해결된다. 기본적으로 내 모델에 정보 중 일부를 제공하기 위해 내부 조인을 사용하여 여러 테이블의 결과를 결합합니다. 그런 다음 뷰에 전달합니다. 쿼리는 첫 번째 결과 (올바른 결과) 만 반환하고 나타나는 것보다 더 많은 시간을 반환하지만 다른 결과는 표시하지 않습니다. 즉, 다른 결과를 표시하지 않으면 서 첫 번째 결과를 여러 번 반복합니다.
그래서 출력이 같은 말을했는데 경우 (이것은 단지 예입니다)
Name Task Name Status
Derp Do the Dishes ACTIVE
John Example Task COMPLETE
Jesus Walk on Water IMPOSSIBLE
대신 내 LINQ 구문에 문제가있는 가정
Name Task Name Status
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
Derp Do the Dishes ACTIVE
을 말할 것입니다. 여기
내 컨트롤러 관련 부분 : 여기var TaskInstanceList = taskInstanceService.SelectAll();
var Person = personService.SelectAll();
var Task = taskService.SelectAll();
var Status = statusService.SelectAll();
var NewModel = new TaskLogModelContainer();
NewModel.Tasks = new List<TaskLogModel>();
var results = from ti in TaskInstanceList
join p in Person on ti.personID equals p.personID
join t in Task on ti.taskID equals t.taskID
join s in Status on ti.task_statusID equals s.statusID
select new { Person = p, Task = t, Status = s, Instance = ti };
foreach (var result in results)
{
var obj = new TaskLogModel();
obj.ID = result.Instance.person_taskID;
obj.FirstName = result.Person.FirstName;
obj.LastName = result.Person.LastName;
obj.Description = result.Task.Description;
obj.TaskName = result.Task.Name;
obj.Value = result.Task.Value;
obj.Status = result.Status.Status;
obj.Notes = result.Status.Notes;
NewModel.Tasks.Add(obj);
}
return View(NewModel);
와 나의이다
@model MyProj.Models.TaskLogModelContainer
@{
ViewBag.Title = "index";
}
<h2>@ViewBag.Title</h2>
<table>
<tr>
<th>
Name
</th>
<th>
Task Name
</th>
<th>
Status
</th>
</tr>
@foreach (var item in Model.Tasks)
{
<tr>
<td>@item.FirstName @item.LastName</td>
<td>@item.TaskName</td>
<td>@item.Status</td>
</tr>
}
</table>
가짜 데이터로 코드를 테스트 한 결과 정상적으로 작동합니다. 여기있다 : https://dl.dropboxusercontent.com/u/67454234/Program.cs –
나는 무엇이 문제인지 모르겠다 .... 당신의 쿼리가 여러 행을 기대하는 한 행을 반환하고 있습니까? –
문제를 명확히하기 위해 원래 게시물을 편집합니다 – PlausibleSarge