Problem with converting int to string in Linq to entities

var items = from c in contacts
            select new ListItem
            {
                Value = c.ContactId, //Cannot implicitly convert type 'int' (ContactId) to 'string' (Value).
                Text = c.Name
            };
var items = from c in contacts
            select new ListItem
            {
                Value = c.ContactId.ToString(), //Throws exception: ToString is not supported in linq to entities.
                Text = c.Name
            };

Is there anyway I can achieve this?
Note, that in VB.NET there is no problem use the first snippet it works just great, VB is flexible, im unable to get used to C#’s strictness!!!

15 Answers
15

Leave a Comment