我为每个NumDemande提供了几个id_demande。 我想显示我的demandes distinctBY NumDemande,但我不想选择与该NumDemande关联的第一个id_demande,我想选择包含要显示的id_Etat最大值的id_demande。
我的控制器
public ActionResult ListeDemande()
{
traçabilitérepository=new TraçabilitéDemandeRepository(db);
var listdemandes = (from d in db.Demande_Gabarit
join t in db.Traçabilité_Demande_Gabarit
on d.id_demande equals t.iddemande into ThisList
from t in ThisList.DefaultIfEmpty()
select new
{
NumDemande = d.NumDemande,
Emetteur = d.Emetteur,
Date = d.Date,
Ligne = d.Ligne.designation,
Etat = t.Etat_Demande_Gabarit.EtatDemande
}).ToList().Select(x => new DemandeViewModel()
{
NumDemande = x.NumDemande,
Emetteur = x.Emetteur,
Date = x.Date,
designation = x.Ligne,
EtatDemande = x.Etat
});
return View(listdemandes);
}
我的观点
@model IEnumerable<ViewModel.DemandeViewModel>
@{
ViewBag.Title = "TraitementDemande";
}
<div class="col-xs-12">
<div class="box">
<h2>Liste des demandes</h2>
@using (Html.BeginForm("Recherche", "Demandes", FormMethod.Get))
{
/*<div class="box-tools">
<div class="input-group input-group-sm" style="width: 150px;">
<input type="text" name="table_search" class="form-control pull-right" placeholder="Search">
<div class="input-group-btn">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
</div>
</div>
</div>*/
@Html.TextBox("Search");<input type="submit" value="Search" />
}
@*<p>
@Html.ActionLink("Create New", "Create")
</p>*@
<table class="table table-striped">
<tr>
<th>
N° Demande
</th>
<th>
@Html.DisplayNameFor(model => model.Emetteur)
</th>
<th>
@Html.DisplayNameFor(model => model.Date)
</th>
<th>
Ligne
</th>
<th>
Etat
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.NumDemande)
</td>
<td>
@Html.DisplayFor(modelItem => item.Emetteur)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.designation)
</td>
<td>
@Html.DisplayFor(modelItem => item.EtatDemande)
</td>
<td>
@Html.ActionLink("Details", "Details", new { num = item.NumDemande,iddemande=item.id_demande })
</td>
</tr>
}
</table>
</div>
</div>
请帮助,谢谢。