我想將數據庫模型映射到視圖模型,同時分割爲未映射的屬性的真正假查找:Linq IGrouping,ILookup或IDIctionary劃分並映射到新的IEnumerable
對應的屬性會像
public IDictionary<bool,IEnumerable<SelectListItem>>
NoConsentAttemptReasons { get; set; }
,這樣我可以通過
foreach (SelectListItem item in NoConsentAttemptReasons[true])
迭代,但我不確定的LINQ實現這一目標。試圖重複排列,包括:
model.NoConsentAttemptReasons = ScreenService
.GetNoConsentReasons()
.ToLookup(r=>r.Unaware, r => new SelectListItem
{
Text = r.Description,
Selected = model.NoConsentAttemptId == r.Id,
Value = r.Id.ToString()
});
,但當然我不是映射到<布爾,IEnumerable的<SelectListItem> >而是<布爾,selectListItem >
感謝您的幫助。
謝謝你 - 你是絕對正確的我不需要額外的層 - 非常感謝你 – Brent