How to use Lambda in LINQ select statement

前端 未结 5 2001
孤独总比滥情好
孤独总比滥情好 2020-12-04 08:01

I am trying to select stores using a lambda function and converting the result to a SelectListItem so I can render it. However it is throwing a \"Type of Expression

5条回答
  •  萌比男神i
    2020-12-04 08:41

    Why not just use all Lambda syntax?

    database.Stores.Where(s => s.CompanyID == curCompany.ID)
                   .Select(s => new SelectListItem
                       {
                           Value = s.Name,
                           Text = s.ID
                       });
    

提交回复
热议问题