I wrote the following method to fill a DropDownList and it works. However I would like to write the proper LINQ Query using Lambda expression as the first parameter of the SelectList initializer instead of the comprehension query that is there. My goal is to concatenate the EventmId and EventmTitle properties of the Eventm Object to appear as selections in the DropDownList.
Thank you!
private void PopulateEventmsDropDownList(object selectedEventm = null)
{
var eventmsQuery = unitOfWork.EventmRepository.Get(
orderBy: q => q.OrderBy(d => d.EventmId));
ViewBag.EventmID = new SelectList(
(from s in eventmsQuery select new { EventmId = s.EventmId.ToString(),
FullID = s.EventmId + " " + s.EvtTitle }),
"EventmId", "FullID", selectedEventm);
}
After some trial and error using LINQPad I came up with this Lambda Expression (to replace the comprehension query) in the SelectList as follows: