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