I am trying to select stores using a lambda function and convert the result to SelectListItem so that I can display it. However, he throws " Type of expression in Select Clause is Incorrect ":
IEnumerable<SelectListItem> stores = from store in database.Stores where store.CompanyID == curCompany.ID select (s => new SelectListItem { Value = s.ID, Text = s.Name} ); ViewBag.storeSelector = stores;
What am I doing wrong?
EDIT:
Also, how do I convert Int to String in this situation? The following does not work:
select (s => new SelectListItem { Value = s.ID.ToString(), Text = s.Name} ); select (s => new SelectListItem { Value = s.ID + "", Text = s.Name} );
EDIT 2:
Output the conversion of Int to String. It is typical for Microsoft to forget to enable the int2string conversion function. Here is the actual workaround that everyone uses, with fully working syntax:
select new SelectListItem { Value = SqlFunctions.StringConvert((double)store.ID), Text = store.Name };
To call this situation absurd is an understatement.
c # lambda linq asp.net-mvc
Bill Mar 22 '13 at 18:56 2013-03-22 18:56
source share