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
};
无论如何,我能做到这一点吗?请注意,在VB.NET中使用第一个片段没有问题,它工作得很好,VB灵活,我无法适应C#的严格性!!!