In this case I'm transforming from a List of EF Entities (called promotions here) to a list of MVC SelectListItems.
Standard Linq stylee
var query = from promo in promotions
select new SelectListItem { Text = promo.Name, Value = promo.Id.ToString() };
Enumerable Linq Method stylee
var query = promotions.Select(promo => new SelectListItem() { Text = promo.Name, Value = promo.Id.ToString() });
To get a List out, you just do query.ToList().
No comments:
Post a Comment
Comments are very welcome but are moderated to prevent spam.