开发者

Inline lambda - get rate with latest date

The MVC ViewPage contains Users (intranet.Model.User). Each user may have one or more rates of pay represented in the model as intranet.model.User.UserRates.

I need to be able to display the latest rate of pay per user using an inline Lambda expression but I am having no success (an error message is displayed rather than the rate of pay).

My latest incarnation is:

     
        <% var latestRate = item.UserRates
                               .GroupBy(hr=>hr.rate)
                               .Select(g=>g.Single(
                                  d=>d.effective == g.Max(m=>m.effective)开发者_JAVA技巧)
                                ); %>

<%= Html.Encode(latestRate) %> </td>

Error message in column is:

System.Linq.Enumerable+WhereSelectEnumerableIterator2[System.Linq.IGrouping2[System.Decimal,intranet.Models.UserRate],intranet.Models.UserRate]


I can't figure out exactly what your data looks like, but couldn't you do something like this?

var latestRate = item.UserRates
                     .OrderByDescending(x => x.effective)
                     .First();


Final iteration (for now):

  <% var userRate = item.UserRates
                        .OrderByDescending(hr=>hr.effective)
                        .FirstOrDefault() ?? new intranet.Models.UserRate(); %>

  <td class="hrlyRate">                                         
      <%= Html.Encode(string.Format("{0:0.000}", userRate.rate))%>
  </td> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜