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