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# 的严格性!!!