I am trying to create a selectlist in c#. My code :
var ceremonies = db.Ceremonies;
var Ceremonies =
from c in ceremonies
select new SelectListItem
{
Text = c.Name + "_" + c.Date,
Value = c.Id.ToString()
};
But here i am getting exception something like ToString() method not supported. Whats the problem ?
Your query is being transformed into SQL – but the call to
ToStringcan’t be handled properly. Generally the simplest way of fixing this is to effectively split the query into the part that needs to be done in the database, then switch to LINQ to Objects viaAsEnumerable:As an aside, declaring two local variables which vary only by case gives pretty nasty readability.