0

目標: 期日が今日の日付以下であるすべてのパネルを取得します。

エンティティ/データベース図: ここに画像の説明を入力 コントローラ:

    public ActionResult Index(PanelViewModel panelViewModel) 
    {
        panelViewModel.Panels = _panelRepository.GetPanels()
                                  .Where(p => p.PanelApplicationForms.Count > 0
                                          && p.IsPublish
                                          && p.PanelApplicationForms != null)
                                  .OrderBy(t => t.Title);

        return View(panelViewModel);
    }
4

2 に答える 2

0

試す

public ActionResult Index(PanelViewModel panelViewModel) 
{
    var proj  = _panelRepository.GetPanels()
                              .Where(p => p.PanelApplicationForms.Count > 0
                                      && p.PanelApplicationForms
                                         .Any(f => f.PanelApplicationFormVersions
                                           .Any(v => v.DueDate <= today))
                                      && p.IsPublish
                                      && p.PanelApplicationForms != null)
                              .OrderBy(t => t.Title)
                              .Select(p => new { 
                                          Panel = p, 
                                          PanelApplicationForms = p.PanelApplicationForms
                                           .Where(f => f.PanelApplicationFormVersions
                                           .Any(v => v.DueDate <= today))
                                          })
                              .ToList();

    panelViewModel.Panels = proj.Select(p => p.Panel);

    return View(panelViewModel);
}
于 2012-12-18T04:27:09.577 に答える
0

@Eranga上記の回答とコメントに感謝します。私はそれを次のようにして動作させました、

コントローラ:

panelViewModel.Panels = _panelRepository.GetPanels()
                                 .Where(p => p.PanelApplicationForms.Count > 0
                                                    && p.PanelApplicationForms
                                                           .Any(f => f.IsPublish
                                                                     &&
                                                                     f.PanelApplicationFormVersions.OrderByDescending(v => v.VersionNumber).
                                                                         First().DueDate >= DateTime.Today
                                                                     && f.PanelApplicationFormVersions.Count > 0
                                                           )
                                                    && p.PanelApplicationForms != null)
                                          .OrderBy(t => t.Title);

意見:

                       @foreach (var panelApplicationFormItem in panelItem.PanelApplicationForms.Where(panelApplicationFormItem => panelApplicationFormItem.IsPublish))
                        {
                            var panelApplicationFormVersion = panelApplicationFormItem.PanelApplicationFormVersions.OrderByDescending(v => v.VersionNumber).First();
                            if (panelApplicationFormVersion.DueDate >= DateTime.Today)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(modelItem => panelApplicationFormItem.Title)
                                    </td>
                                    <td class="span2">
                                        @if (panelApplicationFormItem.PanelApplicationFormVersions.Count > 0)
                                        {

                                            @Html.DisplayFor(modelItem => panelApplicationFormVersion.DueDate)
                                        }
                                    </td>
                                    <td class="span2">
                                        @{
                                            //var isApplicationAlreadyExist = panelApplicationFormVersion.Id.IsApplicationAlreadyExist()
                                        }
                                        @if (panelApplicationFormVersion != null)
                                        {
                                            <a href="~/Application/Apply/@panelApplicationFormVersion.Id?versionNumber=@panelApplicationFormVersion.VersionNumber" class="btn">Apply</a>
                                        }
                                        else
                                        {
                                            <a href="#" class="btn">Sum</a>
                                        @*<p>No versions available to apply</p>*@
                                        }
                                    </td> 
                                </tr>
                            }
                        }
于 2013-01-09T00:24:38.250 に答える